Mario Demontis
Mario Demontis

Reputation: 484

c++14 static constexpr auto with odr usage

I have the following c++14 code:

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

This is perfectly fine, provided that T::foo() is a constexpr as well.

Now I have that something is ODR used, so I need to provide a namespace declaration. What syntax should I use?

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

Doesn't work. Thanks!

Upvotes: 5

Views: 271

Answers (1)

max66
max66

Reputation: 66210

What about passing through a using defined typename ?

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;

Upvotes: 2

Related Questions