【发布时间】:2017-06-07 14:13:32
【问题描述】:
是否可以这样做:
template<class T, T type>
constexpr auto f(/* type used in some way... */) // -> decltype (etc. in case of C++11)
{
return std::integral_constant<T,t>{};
}
constexpr auto z = f(3); // z is deduced as an integral_constant<int,3>;
使用运行时值肯定是不可能的,但在这种情况下 3 是编译时值。也许有人知道一些我不知道的技巧......
[编辑] constexpr auto z2 = f(); // 这样也可以
我只是想避免重复输入..
【问题讨论】:
标签: c++ c++11 templates template-meta-programming type-deduction