名前空間
変種
操作

std::remove_cvref

From cppreference.com
< cpp‎ | types
 
 
メタプログラミングライブラリ
型特性
型のカテゴリ
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
型のプロパティ
(C++11)
(C++11)
(C++14)
(C++11)(C++26で非推奨)
(C++11)(C++20まで*)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
サポートされている操作
関係とプロパティクエリ
型の変更
(C++11)(C++11)(C++11)
型の変換
(C++11)(C++23で非推奨)
(C++11)(C++23で非推奨)
(C++11)
remove_cvref
(C++20)
(C++11)(C++20まで*)(C++17)

(C++11)
(C++17)
コンパイル時有理数演算
コンパイル時整数シーケンス
 
ヘッダ <type_traits> で定義
template< class T >
struct remove_cvref;
(C++20以降)

T が参照型の場合、その最上位の cv-修飾子を除去した T が参照する型であるメンバ typedef type を提供します。それ以外の場合、type は最上位の cv-修飾子を除去した T です。

プログラムが 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)
関数引数を値渡しする際の型変換を適用する
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)