std::remove_cvref
From cppreference.com
| ヘッダ <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)>); }
[編集] 関連項目
| (C++11)(C++11)(C++11) |
与えられた型から const および/または volatile 修飾子を削除する (クラステンプレート) |
| (C++11) |
与えられた型から参照を削除する (クラステンプレート) |
| (C++11) |
関数引数を値渡しする際の型変換を適用する (クラステンプレート) |