◐ Shell
clean mode source ↗

std::remove_cvref - cppreference.com

提供: cppreference.com

<tbody> </tbody>

template< class T > struct remove_cvref;

(C++20以上)

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

メンバ型

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

ヘルパー型

<tbody> </tbody>

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

関連項目