Starting from C++20 one can use auto
template argument to implement integral constant:
template <auto Value>
struct integral_constant2
: std::integral_constant<decltype(Value), Value> {};
which can be used instead of more verbose variant std::integral_constant that has two template arguments.
Sure its easier to write f(std::integral_constant2<123>{});
instead of more verbose f(std::integral_constant<int, 123>{});
. More than that you may not know type in advance if you have complex compile-time expression.
My question is whether there exists in C++20 std library anything like integral_constant2
mentioned above, not to reinvent wheel? Or at least some std constexpr
function std::make_integral_constant(123)
that deduces std::integral_constant
's template params?
auto
parameter to any template takingtypename T, T value
, though I am not aware of any higher order template in the standard lib