Conditionally member function constexpr

Suppose I have a template class

template <typename T> class foo { T m; decltype(auto) f() { return mf(); } }; 

How can I give foo:f() the constexpr specifier only if T::f() is constexpr?

0
c ++ templates c ++ 14 constexpr
source share
1 answer

You just click constexpr on it:

 constexpr decltype(auto) f() { return mf(); } 

Yes, it works fine even if T::f() not constexpr ; such a function simply cannot be used in constant expressions. See [dcl.constexpr] / 6 .

+3
source share

All Articles