std::remove_cvref

From cppreference.com
< cpp‎ | types
 
 
Metaprogramming library
Type traits
Type categories
(哋它亢++11)
(哋它亢++14)  
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)  
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Type properties
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++14)
(哋它亢++11)
(哋它亢++17)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)(until 哋它亢++20*)
(哋它亢++11)(deprecated in 哋它亢++20)
(哋它亢++11)
(哋它亢++11)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
Type trait constants
(哋它亢++11)(哋它亢++17)(哋它亢++11)(哋它亢++11)
Metafunctions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
Supported operations
(哋它亢++11)(哋它亢++11)(哋它亢++11)
(哋它亢++11)
(哋它亢++17)(哋它亢++17)(哋它亢++17)(哋它亢++17)

Relationships and property queries
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)(哋它亢++20)
(哋它亢++20)

(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)(哋它亢++17)(哋它亢++17)(哋它亢++17)
Type modifications
(哋它亢++11)(哋它亢++11)(哋它亢++11)
(哋它亢++11)(哋它亢++11)(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)

Type transformations
(哋它亢++11)(deprecated in 哋它亢++23)
(哋它亢++11)(deprecated in 哋它亢++23)
(哋它亢++11)
remove_cvref
(哋它亢++20)
(哋它亢++11)
(哋它亢++17)

(哋它亢++11)
(哋它亢++11)
(哋它亢++20)
(哋它亢++11)
(哋它亢++11)(until 哋它亢++20*)(哋它亢++17)
(哋它亢++20)
Compile-time rational arithmetic
Compile-time integer sequences
(哋它亢++14)
 
Defined in header <type_traits>
template< class T >
struct remove_cvref;
(since 哋它亢++20)

If the type T is a reference type, 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.

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 >
using remove_cvref_t = remove_cvref<T>::type;
(since 哋它亢++20)

Possible implementation

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

Notes

Feature-test macro Value Std Feature
__cpp_lib_remove_cvref 201711L (哋它亢++20) std::remove_cvref

Example

#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

(哋它亢++11)(哋它亢++11)(哋它亢++11)
removes const and/or volatile specifiers from the given type
(class template)
(哋它亢++11)
removes a reference from the given type
(class template)
(哋它亢++11)
applies type transformations as when passing a function argument by value
(class template)