c ++ 14 静态 constexpr 自动与 odr 用法

Mar*_*ddu 5 c++ templates constexpr auto c++14

我有以下 c++14 代码:

template<typename T>
struct Test{
    static constexpr auto something{T::foo()};
};
Run Code Online (Sandbox Code Playgroud)

这完全没问题,前提是它T::foo()也是一个constexpr

现在我已经使用了somethingODR,所以我需要提供一个命名空间声明。我应该使用什么语法?

template<typename T>
constexpr auto Test<T>::something;
Run Code Online (Sandbox Code Playgroud)

不起作用。谢谢!

max*_*x66 2

传递using定义的类型名怎么样?

template <typename T>
struct Test
 {
   using someType = decltype(T::foo());

   static constexpr someType something{T::foo()};
 };

template<typename T>
constexpr typename Test<T>::someType Test<T>::something;
Run Code Online (Sandbox Code Playgroud)