Namespaces
Variants

std:: remove_cvref

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
remove_cvref
(C++20)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
定義先ヘッダ <type_traits>
template < class T >
struct remove_cvref ;
(C++20以降)

T が参照型である場合、メンバーtypedef type を提供します。これは T によって参照される型から最上位のcv修飾子を除去したものです。それ以外の場合、 type T から最上位のcv修飾子を除去したものです。

プログラムが std::remove_cvref に対する特殊化を追加する場合、動作は未定義です。

目次

メンバー型

名前 定義
type T によって参照される型、または T が参照でない場合は T 自身(トップレベルのcv修飾子が除去されたもの)

ヘルパー型

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

実装例

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

注記

機能テスト マクロ 標準 機能
__cpp_lib_remove_cvref 201711L (C++20) std::remove_cvref

#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)>);
}

関連項目

指定された型から const および/または volatile 指定子を除去する
(クラステンプレート)
指定された型から参照を除去する
(クラステンプレート)
(C++11)
関数引数を値渡しするときと同様の型変換を適用する
(クラステンプレート)