c++14 static constexpr auto 与 odr 用法
c++14 static constexpr auto with odr usage
我有以下 c++14 代码:
template<typename T>
struct Test{
static constexpr auto something{T::foo()};
};
这很好,前提是 T::foo()
也是 constexpr
。
现在我知道 something
使用了 ODR,所以我需要提供命名空间声明。我应该使用什么语法?
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;
我有以下 c++14 代码:
template<typename T>
struct Test{
static constexpr auto something{T::foo()};
};
这很好,前提是 T::foo()
也是 constexpr
。
现在我知道 something
使用了 ODR,所以我需要提供命名空间声明。我应该使用什么语法?
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;