Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Makes an integral constant from a type and value.
Syntax
template<class T, T v>
struct integral_constant {
static constexpr T value = v;
typedef T value_type;
typedef integral_constant<T, v> type;
constexpr operator value_type() const noexcept;
constexpr value_type operator()() const noexcept;
};
Parameters
T
The type of the constant.
v
The value of the constant.
Remarks
The integral_constant class template, when specialized with an integral type T and a value v of that type, represents an object that holds a constant of that integral type with the specified value. The member named type is an alias for the generated template specialization type, and the value member holds the value v used to create the specialization.
The bool_constant class template is an explicit partial specialization of integral_constant that uses bool as the T argument.
Example
// std__type_traits__integral_constant.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>
int main()
{
std::cout << "integral_constant<int, 5> == "
<< std::integral_constant<int, 5>::value << std::endl;
std::cout << "integral_constant<bool, false> == " << std::boolalpha
<< std::integral_constant<bool, false>::value << std::endl;
return (0);
}
integral_constant<int, 5> == 5
integral_constant<bool, false> == false
Requirements
Header: <type_traits>
Namespace: std