c++ - Is it possible to obtain a type from decltype? -
decltype returns full type of expression/entity. possible type?
for example, possible make p have type t in case?
class t; t t; const t& tt = t; decltype(tt) p; //decltype makes const t& same tt
it depends on entirely on want in cases of cv t* , cv t[n]. if in of cases want t, you'll need write type trait:
template <typename t> struct tag { using type = t; }; template <typename t> struct just_t : std::conditional_t<std::is_same<std::remove_cv_t<t>,t>::value, tag<t>, just_t<std::remove_cv_t<t>>> { }; template <typename t> struct just_t<t*> : just_t<t> { }; template <typename t> struct just_t<t&> : just_t<t> { }; template <typename t, size_t n> struct just_t<t[n]> : just_t<t> { }; template <typename t> struct just_t<t[]> : just_t<t> { }; if you're okay pointers staying , arrays decaying pointers, simply:
template <typename t> using just_t = std::decay_t<t>;
Comments
Post a Comment