std::remove_cvref(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ std::remove_cvref(3) ✨

okay bestie, welcome to the C++ Standard Libary manual page for std::remove_cvref β€” yes, that's the manual name, and it's giving "type-trait bestie who removes a reference and then clears the cv-qualifiers" energy πŸ’…. This page is literally std::remove_cvref(3), and we're about to get your types together.


πŸ’– NAME πŸ’–

  • std::remove_cvref β€” std::remove_cvref

🌸 Synopsis 🌸

Defined in header <type_traits>:

template< class T >              (since C++20)
struct remove_cvref;

If the type T is a reference type, this provides the member typedef type which is the type referred to by T with its topmost cv-qualifiers removed. Otherwise type is T with its topmost cv-qualifiers removed. ✨

🚨 If the program adds specializations for std::remove_cvref, the behavior is undefined. Like, do not customize this one, bestie β€” that's not the vibe, fr fr.

πŸŽ€ Member types πŸŽ€

Name β†’ Definition:

  • type β€” the type referred by T or T itself if it is not a reference, with top-level cv-qualifiers removed.

πŸ¦‹ Helper types πŸ¦‹

template< class T >                            (since C++20)
using remove_cvref_t = remove_cvref<T>::type;

πŸ’… Possible implementation πŸ’…

template<class T>
struct remove_cvref
{
    using type = std::remove_cv_t<std::remove_reference_t<T>>;
};

πŸ”₯ Notes πŸ”₯

Feature-test macro table, but make it cute:

  • Feature-test macro: __cpp_lib_remove_cvref
  • Value: 201711L
  • Std: (C++20)
  • Feature: std::remove_cvref

🌈 Example 🌈

// Run this code

#include <type_traits>

int main()
{
    static_assert(std::is_same_v<std::remove_cvref_t<int>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<int&>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<int&&>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int&>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int[2]>, int[2]>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int(&)[2]>, int[2]>);
    static_assert(std::is_same_v<std::remove_cvref_t<int(int)>, int(int)>);
}

🌟 See also 🌟

  • remove_cv β€” (C++11), class template.
  • remove_const β€” (C++11), class template.
  • remove_volatile β€” removes const and/or volatile specifiers from the given type; (C++11), class template.
  • remove_reference β€” removes a reference from the given type; (C++11), class template.
  • decay β€” applies type transformations as when passing a function argument by value; (C++11), class template.

cute sign-off: this page is from http://cppreference.com, version/date 2024.06.10, and it's literally std::remove_cvref(3) β€” slay, go remove those qualifiers, bestie πŸ’–πŸ«Ά

πŸ“¦ where this page comes from