名前空間
変種
操作

std::remove_cvref

提供: cppreference.com
< cpp‎ | types
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
型サポート
型の性質
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++20未満)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
定数評価文脈
サポートされている操作
関係と性質の問い合わせ
型変更
(C++11)(C++11)(C++11)
型変換
(C++11)
remove_cvref
(C++20)
(C++11)
(C++17)
(C++11)(C++20未満)(C++17)
 
ヘッダ <type_traits> で定義
template< class T >
struct remove_cvref;
(C++20以上)

T が参照型であれば、最上段の cv 修飾を除去した T の参照先の型であるメンバ型 type が提供されます。 そうでなければ、 type は最上段の cv 修飾が除去された T です。

目次

[編集] メンバ型

名前 定義
type 最上段の cv 修飾が除去された、 T の参照先の型、または参照でなければ T 自身

[編集] ヘルパー型

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

[編集] 実装例

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

[編集]

#include <iostream>
#include <type_traits>
 
int main()
{
    std::cout << std::boolalpha
              << std::is_same_v<std::remove_cvref_t<int>, int> << '\n'
              << std::is_same_v<std::remove_cvref_t<int&>, int> << '\n'
              << std::is_same_v<std::remove_cvref_t<int&&>, int> << '\n'
              << std::is_same_v<std::remove_cvref_t<const int&>, int> << '\n'
              << std::is_same_v<std::remove_cvref_t<const int[2]>, int[2]> << '\n'
              << std::is_same_v<std::remove_cvref_t<const int(&)[2]>, int[2]> << '\n'
              << std::is_same_v<std::remove_cvref_t<int(int)>, int(int)> << '\n';
}

出力:

true
true
true
true
true
true
true

[編集] 関連項目

指定された型から const, volatile またはその両方の指定子を削除します
(クラステンプレート) [edit]
指定された型から参照を削除します
(クラステンプレート) [edit]
(C++11)
関数に引数を値渡ししたときと同様の型変換を適用します
(クラステンプレート) [edit]