c++14 static constexpr auto with odr usage

c++14 static constexpr auto with odr usage

本文关键字:odr usage with auto static constexpr c++14      更新时间:2023-10-16

我有以下 c++14 代码:

template<typename T>
struct Test{
    static constexpr auto something{T::foo()};
};

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

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

template<typename T>
constexpr auto Test<T>::something;

不行。谢谢!

传递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;