最終更新日時(UTC):
が更新

履歴 編集

class template
<type_traits>

std::remove_const(C++11)

namespace std {
  template <class T>
  struct remove_const {
    using type = ;
  };

  template <class T>
  using remove_const_t = typename remove_const<T>::type; // C++14
}

概要

型のconst修飾を除去する。

効果

remove_constは、型Tに含まれる最上位のconst修飾を除去した型を、メンバ型typeとして定義する。

#include <type_traits>

static_assert(std::is_same<
        std::remove_const<const int>::type,
        int
    >::value,
    "transform from const int to int");

static_assert(std::is_same<
        std::remove_const<const volatile int>::type,
        volatile int
    >::value,
    "transform from const volatile int to volatile int");

static_assert(std::is_same<
        std::remove_const<const int&>::type,
        const int&
    >::value,
    "transform from const int& to const int&");

static_assert(std::is_same<
        std::remove_const<const int*>::type,
        const int*
    >::value,
    "transform from const int* to const int*");

static_assert(std::is_same<
        std::remove_const<const int* const>::type,
        const int*
    >::value,
    "transform from const int* const to const int*");

int main() {}

出力

バージョン

言語

  • C++11

処理系

  • Clang: 3.0
  • GCC: 4.3.6
  • Visual C++: 2008 (std::tr1), 2010, 2012, 2013, 2015
    • remove_const_tは2013から

参照