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?
foo:f()
T::f()
You just click constexpr on it:
constexpr
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 .