📄 type_traits.qbk
字号:
};
__type The same type as `T const` for all `T`.
__std_ref 3.9.3.
__compat If the compiler does not support partial specialization of class-templates
then this template will compile, but the member `type` will always be the same as
type `T` except where __transform_workaround have been applied.
__header ` #include <boost/type_traits/add_const.hpp>` or ` #include <boost/type_traits.hpp>`
[table Examples
[ [Expression] [Result Type]]
[[`add_const<int>::type`][`int const`]]
[[`add_const<int&>::type`] [`int&`]]
[[`add_const<int*>::type`] [`int* const`]]
[[`add_const<int const>::type`] [`int const`]]
]
[endsect]
[section:add_cv add_cv]
template <class T>
struct add_cv
{
typedef __below type;
};
__type The same type as `T const volatile` for all `T`.
__std_ref 3.9.3.
__compat If the compiler does not support partial specialization of class-templates
then this template will compile, but the member `type` will always be the same as
type `T` except where __transform_workaround have been applied.
__header ` #include <boost/type_traits/add_cv.hpp>` or ` #include <boost/type_traits.hpp>`
[table Examples
[ [Expression] [Result Type]]
[[`add_cv<int>::type`][`int const volatile`]]
[[`add_cv<int&>::type`] [`int&`]]
[[`add_cv<int*>::type`] [`int* const volatile`]]
[[`add_cv<int const>::type`] [`int const volatile`]]
]
[endsect]
[section:add_pointer add_pointer]
template <class T>
struct add_pointer
{
typedef __below type;
};
__type The same type as `remove_reference<T>::type*`.
The rationale for this template
is that it produces the same type as `TYPEOF(&t)`,
where `t` is an object of type `T`.
__std_ref 8.3.1.
__compat If the compiler does not support partial specialization of class-templates
then this template will compile, but the member `type` will always be the same as
type `T` except where __transform_workaround have been applied.
__header ` #include <boost/type_traits/add_pointer.hpp>` or ` #include <boost/type_traits.hpp>`
[table Examples
[ [Expression] [Result Type]]
[[`add_pointer<int>::type`][`int*`]]
[[`add_pointer<int const&>::type`] [`int const*`]]
[[`add_pointer<int*>::type`] [`int**`]]
[[`add_pointer<int*&>::type`] [`int**`]]
]
[endsect]
[section:add_reference add_reference]
template <class T>
struct add_reference
{
typedef __below type;
};
__type If `T` is not a reference type then `T&`, otherwise `T`.
__std_ref 8.3.2.
__compat If the compiler does not support partial specialization of class-templates
then this template will compile, but the member `type` will always be the same as
type `T` except where __transform_workaround have been applied.
__header ` #include <boost/type_traits/add_reference.hpp>` or ` #include <boost/type_traits.hpp>`
[table Examples
[ [Expression] [Result Type]]
[[`add_reference<int>::type`][`int&`]]
[[`add_reference<int const&>::type`] [`int const&`]]
[[`add_reference<int*>::type`] [`int*&`]]
[[`add_reference<int*&>::type`] [`int*&`]]
]
[endsect]
[section:add_volatile add_volatile]
template <class T>
struct add_volatile
{
typedef __below type;
};
__type The same type as `T volatile` for all `T`.
__std_ref 3.9.3.
__compat If the compiler does not support partial specialization of class-templates
then this template will compile, but the member `type` will always be the same as
type `T` except where __transform_workaround have been applied.
__header ` #include <boost/type_traits/add_volatile.hpp>` or ` #include <boost/type_traits.hpp>`
[table Examples
[ [Expression] [Result Type]]
[[`add_volatile<int>::type`][`int volatile`]]
[[`add_volatile<int&>::type`] [`int&`]]
[[`add_volatile<int*>::type`] [`int* volatile`]]
[[`add_volatile<int const>::type`] [`int const volatile`]]
]
[endsect]
[section:aligned_storage aligned_storage]
template <std::size_t Size, std::size_t Align>
struct aligned_storage
{
typedef __below type;
};
__type a built-in or POD type with size `Size` and an alignment
that is a multiple of `Align`.
__header ` #include <boost/type_traits/aligned_storage.hpp>` or ` #include <boost/type_traits.hpp>`
[endsect]
[section:alignment_of alignment_of]
template <class T>
struct alignment_of : public __integral_constant<std::size_t, ALIGNOF(T)> {};
__inherit Class template alignment_of inherits from
`__integral_constant<std::size_t, ALIGNOF(T)>`, where `ALIGNOF(T)` is the
alignment of type T.
['Note: strictly speaking you should only rely on
the value of `ALIGNOF(T)` being a multiple of the true alignment of T, although
in practice it does compute the correct value in all the cases we know about.]
__header ` #include <boost/type_traits/alignment_of.hpp>` or ` #include <boost/type_traits.hpp>`
__examples
[:`alignment_of<int>` inherits from `__integral_constant<std::size_t, ALIGNOF(int)>`.]
[:`alignment_of<char>::type` is the type `__integral_constant<std::size_t, ALIGNOF(char)>`.]
[:`alignment_of<double>::value` is an integral constant
expression with value `ALIGNOF(double)`.]
[:`alignment_of<T>::value_type` is the type `std::size_t`.]
[endsect]
[section:extent extent]
template <class T, std::size_t N = 0>
struct extent : public __integral_constant<std::size_t, EXTENT(T,N)> {};
__inherit Class template extent inherits from `__integral_constant<std::size_t, EXTENT(T,N)>`,
where `EXTENT(T,N)` is the number of elements in the N'th array dimention of type `T`.
If `T` is not an array type, or if `N > __rank<T>::value`, or if the N'th array bound
is incomplete, then `EXTENT(T,N)` is zero.
__header ` #include <boost/type_traits/extent.hpp>` or ` #include <boost/type_traits.hpp>`
__examples
[:`extent<int[1]>` inherits from `__integral_constant<std::size_t, 0>`.]
[:`extent<double[2][3][4], 1>::type` is the type `__integral_constant<std::size_t, 3>`.]
[:`extent<int[4]>::value` is an integral constant
expression that evaluates to /4/.]
[:`extent<int[][2]>::value` is an integral constant
expression that evaluates to /0/.]
[:`extent<int[][2], 1>::value` is an integral constant
expression that evaluates to /2/.]
[:`extent<int*>::value` is an integral constant
expression that evaluates to /0/.]
[:`extent<T>::value_type` is the type `std::size_t`.]
[endsect]
[section:function_traits function_traits]
[def __argN '''arg<replaceable>N</replaceable>_type''']
template <class T>
struct function_traits
{
static const std::size_t arity = __below;
typedef __below result_type;
typedef __below __argN;
};
The class template function_traits will only compile if:
* The compiler supports partial specialization of class templates.
* The template argument `T` is a /function type/, note that this ['[*is not]]
the same thing as a /pointer to a function/.
[table Function Traits Members
[[Member] [Description]]
[[`function_traits<T>::arity`]
[An integral constant expression that gives the number of arguments accepted by the function type `F`.]]
[[`function_traits<T>::result_type`]
[The type returned by function type `F`.]]
[[`function_traits<T>::__argN`]
[The '''<replaceable>N</replaceable>th''' argument type of function type `F`, where `1 <= N <= arity` of `F`.]]
]
[table Examples
[[Expression] [Result]]
[[`function_traits<void (void)>::arity`] [An integral constant expression that has the value 0.]]
[[`function_traits<long (int)>::arity`] [An integral constant expression that has the value 1.]]
[[`function_traits<long (int, long, double, void*)>::arity`] [An integral constant expression that has the value 4.]]
[[`function_traits<void (void)>::result_type`] [The type `void`.]]
[[`function_traits<long (int)>::result_type`] [The type `long`.]]
[[`function_traits<long (int)>::arg0_type`] [The type `int`.]]
[[`function_traits<long (int, long, double, void*)>::arg3_type`] [The type `void*`.]]
[[`function_traits<long (int, long, double, void*)>::arg4_type`] [A compiler error: there is no `arg4_type` since there are only three arguments.]]
[[`function_traits<long (*)(void)>::arity`] [A compiler error: argument type is a /function pointer/, and not a /function type/.]]
]
[endsect]
[section:has_nothrow_assign has_nothrow_assign]
template <class T>
struct has_nothrow_assign : public __tof {};
__inherit If T is a (possibly cv-qualified) type with a non-throwing assignment-operator
then inherits from __true_type, otherwise inherits from __false_type. Type `T`
must be a complete type.
__compat If the compiler does not support partial-specialization of class
templates, then this template can not be used with function types.
Without some (as yet unspecified) help from the compiler,
`has_nothrow_assign` will never report that a class or struct has a
non-throwing assignment-operator; this is always safe, if possibly sub-optimal.
Currently (May 2005) only Visual C++ 8 has the necessary compiler support to ensure that this
trait "just works".
__header ` #include <boost/type_traits/has_nothrow_assign.hpp>` or ` #include <boost/type_traits.hpp>`
[endsect]
[section:has_nothrow_constructor has_nothrow_constructor]
template <class T>
struct has_nothrow_constructor : public __tof {};
__inherit If T is a (possibly cv-qualified) type with a non-throwing default-constructor
then inherits from __true_type, otherwise inherits from __false_type. Type `T`
must be a complete type.
__compat If the compiler does not support partial-specialization of class
templates, then this template can not be used with function types.
Without some (as yet unspecified) help from the compiler,
`has_nothrow_constructor` will never report that a class or struct has a
non-throwing default-constructor; this is always safe, if possibly sub-optimal.
Currently (May 2005) only Visual C++ 8 has the necessary compiler __intrinsics to ensure that this
trait "just works".
__header ` #include <boost/type_traits/has_nothrow_constructor.hpp>` or ` #include <boost/type_traits.hpp>`
[endsect]
[section:has_nothrow_copy has_nothrow_copy]
template <class T>
struct has_nothrow_copy : public __tof {};
__inherit If T is a (possibly cv-qualified) type with a non-throwing copy-constructor
then inherits from __true_type, otherwise inherits from __false_type. Type `T`
must be a complete type.
__compat If the compiler does not support partial-specialization of class
templates, then this template can not be used with function types.
Without some (as yet unspecified) help from the compiler,
`has_nothrow_copy` will never report that a class or struct has a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -