c++ - Detecting instance method constexpr with SFINAE -
let me first start off noting similar question here: detecting constexpr sfinae. difference in question, detection method works detect static method of class.
i trying detect if can constexpr copy constructed. i'm quite close, here's i've got:
template <class t> constexpr int return_int(t t) { return 0; } template <class t> t& unmove(t&& t) { return t; } template <class ... t> using void_t = void; template <class t, class = void> struct is_constexpr_copy_constructible : std::false_type {}; template <class t> struct is_constexpr_copy_constructible<t, void_t< std::integral_constant<int, return_int(unmove(t{})) > >> : std::true_type {};
the logical progression of ideas in solution follows:
- only constant expression integers can used integer template parameters.
- the result of function call considered constexpr if function constexpr , of parameters constexpr.
- passing value entail making copy.
so write function return_int
gives me constexpr integer iff constexpr expression of type having constexpr copy constructor passed. unmove
ensures copy constructor rather move constructor called.
the problem in order expression in first place, have create type. cannot use declval
standard in tmp, because not unevaluated context; return_int evaluated @ compile time compute type. stuck meta-function detects whether type constexpr copy constructible , constexpr default constructible.
this isn't end of world per se these things tend overlap, it's not ideal. there way around this? fundamentally boils down to:
- i don't see way verify if constexpr in unevaluated context.
- in evaluated context, don't see way instance of type i'm testing in order try make copy without calling constructor.
note in similar question linked, isn't issue because checking static methods, , therefore doesn't need instance.
help?
Comments
Post a Comment