Use 'requires' keyword to support C++20 features by yumeno-yan · Pull Request #666 · taskflow/taskflow · GitHub
Skip to content

Use 'requires' keyword to support C++20 features#666

Open
yumeno-yan wants to merge 1 commit into
taskflow:masterfrom
yumeno-yan:replace_SFINAE_with_requires
Open

Use 'requires' keyword to support C++20 features#666
yumeno-yan wants to merge 1 commit into
taskflow:masterfrom
yumeno-yan:replace_SFINAE_with_requires

Conversation

@yumeno-yan

Copy link
Copy Markdown
Contributor

This pull request updates the code to use C++20's requires keyword in place of SFINAE-based constraints. This change brings several benefits:

  1. Improved Readability: requires offers a cleaner and more intuitive way to express template constraints. In contrast, SFINAE requires constraints to be embedded within the template parameter list using enable_if_t and a special nullptr. By separating the constraints from the template parameters, requires improves code clarity and makes the intention of the template easier to understand.

  2. Enhanced Type Safety: Using requires allows the compiler to more easily validate template parameters against the specified conditions, providing better type-checking and more precise error messages during compilation. When a constraint fails, the compiler can now show exactly which concept check failed, making it easier to pinpoint and fix issues. This helps catch potential errors early, reducing the likelihood of subtle bugs that might arise from more complex SFINAE conditions.

  3. Aligning with C++20 Standards: By using requires, the code is more in line with modern C++ standards. This approach embraces C++20 features, ensuring that the code remains up-to-date and takes advantage of the latest language improvements.

@tsung-wei-huang

Copy link
Copy Markdown
Member

@tsung-wei-huang tsung-wei-huang added the enhancement New feature or request label May 10, 2025
@tsung-wei-huang

Copy link
Copy Markdown
Member

This is a good pull. However, the current doxygen is not able to recognize the keyword require and thus cannot generate docs correctly. Will delay this off until doxygen is capable of doing it.

@bangerth

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants