以下内容似乎不是有效的c ++(-std=c++2a
)。我想基于模板参数var
更改b
的存储类:
#include <type_traits>
template <bool b>
void f() {
typename std::conditional<b, static int, int>::type var;
}
您可以提供f
的完整专业知识,例如:
template <bool b> void f();
template <> void f<true>()
{
int var;
}
template <> void f<false>()
{
static int var;
}
这应该与您要实现的效果相同。