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

履歴 編集

type-alias
<type_traits>

std::true_type(C++11)

namespace std {
  using true_type = integral_constant<bool, true>; // C++14まで
  using true_type = bool_constant<true>;           // C++17から
}

概要

true_typeは、true定数を表す型である。コンパイル時の条件式を扱うために使用される。

#include <type_traits>

static_assert(std::true_type::value == true, "value == true");
static_assert(std::is_same<std::true_type::value_type, bool>::value, "value_type == bool");
static_assert(std::is_same<std::true_type::type, std::true_type>::value, "type == true_type");
static_assert(std::true_type() == true, "true_type() == true");

int main(){}

出力

バージョン

言語

  • C++11

処理系

備考

上の例でコンパイラによってはエラーになる。GCC 4.3.4, 4.5.3, Visual C++ 2010 は integral_constantoperator value_type() を持っていないためエラーになる。

関連項目

参照