C++ std::integral_constant

头文件:#include<type_traits>

可能的实现:

template<class T,T v>
struct integral_constant{
    static constexpr T value = v;
    using value_type = T;
    using type = integral_constant;
    constexpr operator value_type() const noexcept { return value; }
    constexpr value_type operator()() const noexcept { return value; } // if __cplusplus > 201103L.
}

std::integral_constant 包装(wrap)一个指定类型T的一个静态常量,它是C++类型特征(The C++ type traits)的基类。

  • Member constants
Type Definition
value_type T
type std::integral_constant<T,v>
  • Member constants
Name Value
constanexpr T value [static] static constant of type T with value v (public static member constant)
  • Member function
operator value_type
operator value_type returns the wrapped value (public member function)
operator() returns the wrapped value (public member function)
上一篇:Nacos细节篇


下一篇:C++基础-TypeTraits(进行类型的属性判断) 1.is_lvalue_reference(左值引用判断) 2.is_integral(整形判断) 3.is_class(基本类型判段) 4.i