The abbreviated Function Templates
Get an overview of the abbreviated function templates.
We'll cover the following
How to write abbreviated function templates
There is no need for any template parameter list or requires
clause when we use abbreviated function templates. We can directly use the concept where the function arguments are enumerated.
auto add(Number auto a, Number auto b) {
return a+b;
}
Note that after the concept Number
we put auto
. As such, we can see that Number
is a constraint on the type, not a type itself. Imagine if we saw auto add(Number a, Number b)
. As users, how would we know that Number
is not a type, but a concept?
Another thing to note is that, when we use the abbreviated function template, we can mix the types of parameters. We can add an int
to a float
.
Get hands-on with 1400+ tech skills courses.