In C++26, the following code is legal (see p2841r7 and Herb Sutter's article):
template<typename<typename> concept C, template<typename> auto vt, typename T>
requires C<T>
auto f(T v) {
return vt<T> + v;
}
template<typename T>
constexpr auto type_size = sizeof(T);
int main() {
f<std::integral, type_size>(8);
}
However, the following code is still illegal in C++26:
template<typename T>
T f1(T v) { return v + 1; }
template<typename T>
T f2(T v) { return v + 2; }
// There can be many similar template functions like f3, f4, ...
template<template<typename> Fn??? f, typename T>
T g(T v) { return f<T>(v); }
int main() {
g<f1, int>(4);
g<f2, int>(5);
// g<f3, int>(6);
// g<f4, int>(7);
// ...
}
Now that concepts and variable templates are allowed to be the template parameter, why are function templates still not allowed likewise?
template<typename T, T (*f)(T)> T g(T v) { return f(v); }works. Remember to change the order or the template arguments when usingg.Tand even then, you havef2<int>but cannot accessf2<float>.