Search code examples
c++type-traitsc++23

In C++ is there a proposed type traits helper for "copying" reference category and cv-qualification?


For the SFINAE in the hypothetical call operator in this answer I need a type trait that "copies" reference category and const/volatile qualifications from one type to another:

template <typename T, typename U>
using copy_category_and_qualifications_t = [...];

copy_category_and_qualifications_t<int, char>             // char
copy_category_and_qualifications_t<const int&, char>      // const char&
copy_category_and_qualifications_t<volatile int&&, char>  // volatile char&&

I seem to recall some proposed addition to type_traits for this. Does anybody have a reference to this proposal, or know if it was added for C++20 or C++23?


Solution

  • P1450 called this copy_cvref and clone_cvref (the former just applies the qualifiers to the 2nd parameter, the latter first removes the qualifiers from the 2nd parameter). The former is useful, I don't think I've ever personally had a need for the latter.

    P0847 uses like_t and forward_like in a few contexts, like_t there is basically P1450's copy_cvref (the latter is... a significantly better name). forward_like is separately proposed in P2445 (though without the other type trait helper).