带有模板的静态constexpr C ++ 11定义解决方法

时间:2018-11-24 10:48:13

标签: c++ c++11 templates static constexpr

我试图了解C ++ 11在静态constexpr方面的确切工作方式。据我了解,您是否有类似的东西:

template<class T>
struct A
{
static constexpr auto mytuple = std::make_tuple(1,2.0,3);
};
// mytuple will be used by other methods, and it might depend on T

您还需要在.cpp文件中定义mytuple,类似:

template<class T>
constexpr decltype( A<T>::mytuple) A<T>::mytuple; 

但是,如果我将A专门用于其他文件,我是否需要为每种类型再次定义它们呢?似乎没有专业化的定义就可以了,但是当我将其与其他模板功能一起使用时,我开始遇到编译/链接问题。

我知道这已在C ++ 17中修复,并且已弃用,但是我可以使用任何解决方法吗?

0 个答案:

没有答案