|
|
|
|
|
by ncmncm
1758 days ago
|
|
The most important thing to say about this "definitive guide" is that it delays to the end presenting the overwhelmingly most important detail about Concepts: how to use them. The right place to put a concept name, in production code, is in place of "typename" in a template definition, or even better in place of "T" in the function argument declaration. That is, instead of template<typename T>
T add(T a, T b)
requires addable<T> (
return a + b;
)
say template <addable T>
T add(T a, T b) {
return a + b;
}
or auto add(
addable auto a,
addable auto b) {
return a + b;
}
according as whether you want to enforce a and b to have the same type (which is another omission).Most often it is not necessary, and not wanted, to enforce a and b having the same type. |
|
That really depends on what you're trying to do. Presenting these two different declarations as somehow equivalent is very misleading and I'm glad that the author didn't do that.