diff --git a/doc/html/boost_typetraits/category/transform.html b/doc/html/boost_typetraits/category/transform.html index 5ebf62c..7437ec2 100644 --- a/doc/html/boost_typetraits/category/transform.html +++ b/doc/html/boost_typetraits/category/transform.html @@ -63,6 +63,9 @@ template <class... T> struct common_type; +template <class T, class U> +struct copy_cv; + template <class T> struct decay; @@ -101,6 +104,9 @@ template <class T> struct remove_volatile; + +template <class T> +struct type_identity;
#include <boost/type_traits.hpp>
namespace boost { - template <class ...T> struct common_type; + template <class... T> struct common_type; }
- common_type
- is a traits class used to deduce a type common to a several types, useful
- as the return type of functions operating on multiple input types such as
- in mixed-mode arithmetic..
+ common_type
is a traits class
+ used to deduce a type common to a several types, useful as the return type
+ of functions operating on multiple input types such as in mixed-mode arithmetic..
The nested typedef ::type
could be defined as follows:
template <class ...T> +template <class... T> struct common_type; -template <class T, class U, class ...V> -struct common_type<T,U,...V> { - typedef typename common_type<typename common_type<T, U>::type, V...>::type type; +template <class T, class U, class... V> +struct common_type<T, U, V...> { + typedef typename common_type<typename common_type<T, U>::type, V...>::type type; +}; + +template <> +struct common_type<> { }; template <class T> struct common_type<T> { - typedef T type; + typedef typename decay<T>::type type; }; template <class T, class U> struct common_type<T, U> { - typedef decltype(declval<bool>() ? declval<T>() : declval<U>()) type; + typedef typename decay< + decltype( declval<bool>()? + declval<typename decay<T>::type>(): + declval<typename decay<U>::type>() ) + >::type type; };All parameter types must be complete. This trait is permitted to be specialized by a user if at least one template parameter is a user-defined type. Note: Such specializations are required when only - explicit conversions are desired among the common_type + explicit conversions are desired among the
common_type
arguments.Note that when the compiler does not support variadic templates (and the - macro BOOST_NO_VARIADIC_TEMPLATES is defined) then the maximum number of - template arguments is 3. + macro
BOOST_NO_CXX11_VARIADIC_TEMPLATES
+ is defined) then the maximum number of template arguments is 9.- Configuration - macros -
-- When the compiler does not support static assertions then the user can select - the way static assertions are reported. Define -
---
- - BOOST_COMMON_TYPE_USES_STATIC_ASSERT: define it if you want to use Boost.StaticAssert -
-- - BOOST_COMMON_TYPE_USES_MPL_ASSERT: define it if you want to use Boost.MPL - static assertions -
-- The default behavior is to use mpl assertions in this case, but setting BOOST_COMMON_TYPE_USES_STATIC_ASSERT - may reduce compile times and header dependencies somewhat. -
-- Depending on the static assertion used you will have an hint of the failing - assertion either through the symbol or through the text. -
-- When possible common_type is implemented using
-decltype
. - Otherwise when BOOST_COMMON_TYPE_DONT_USE_TYPEOF is not defined it uses Boost.TypeOf. -- Tutorial
- In a nutshell, common_type + In a nutshell,
common_type
is a trait that takes 1 or more types, and returns a type which all of the types will convert to. The default definition demands this conversion be implicit. However the trait can be specialized for user-defined types which want to limit their inter-type conversions to explicit, and yet still want - to interoperate with the common_type + to interoperate with thecommon_type
facility.Example:
template <class T, class U> -complex<typename common_type<T, U>::type> +complex<typename common_type<T, U>::type> operator+(complex<T>, complex<U>);In the above example, "mixed-mode" complex arithmetic is allowed. - The return type is described by common_type. + The return type is described by
common_type
. For example the resulting type of adding acomplex<float>
andcomplex<double>
might be acomplex<double>
.Here is how someone might produce a variadic comparison function:
template <class ...T> -typename common_type<T...>::type +typename common_type<T...>::type min(T... t);This is a very useful and broadly applicable utility.
- + How to get the common type of types with explicit conversions?
@@ -148,23 +125,23 @@ Another choice for the author of the preceding operator could betemplate <class T, class U> -typename common_type<complex<T>, complex<U> >::type +typename common_type<complex<T>, complex<U> >::type operator+(complex<T>, complex<U>);- As the default definition of common_type + As the default definition of
common_type
demands the conversion be implicit, we need to specialize the trait for complex types as follows.template <class T, class U> -struct common_type<complex<T>, complex<U> > { - typedef complex< common_type<T, U> > type; +struct common_type<complex<T>, complex<U> > { + typedef complex< common_type<T, U> > type; };- - How - important is the order of the common_type<> template arguments? + + How + important is the order of the
common_type<>
template arguments?The order of the template parameters is important. @@ -242,9 +219,10 @@ A>.
- - Can - the common_type of two types be a third type? + + Can + the
common_type
of two types + be a third type?Given the preceding example, one might expect
common_type<A,B>::type
to beC
@@ -269,9 +247,10 @@ B>.- - How - common_type behaves with pointers? + + How + does
common_type
behave with + pointers?Consider @@ -305,26 +284,32 @@ Of course the user can always make this specialization.
- - Can - you explain the pros/cons of common_type against Boost.Typeof? + + Can + you explain the pros/cons of
common_type
+ against Boost.Typeof?- Even if they appear to be close,
common_type
+ Even if they appear to be close,common_type
andtypeof
have different purposes. You usetypeof
- to get the type of an expression, while you use common_type + to get the type of an expression, while you usecommon_type
to set explicitly the type returned of a template function. Both are complementary, - and indeed common_type - is equivalent todecltype(declval<bool>() ? declval<T>() - : declval<U>())
+ and indeedcommon_type
is + approximately equivalent todecltype(declval<bool>() + ? declval<T>() + : declval<U>())
.- common_type - is also similar to promote_args<class ...T> in boost/math/tools/promotion.hpp, - though it is not exactly the same as promote_args either. common_type<T1, - T2>::type simply represents the result of some operation on T1 and T2, - and defaults to the type obtained by putting T1 and T2 into a conditional +
common_type
is also similar + topromote_args<class ...T>
in +boost/math/tools/promotion.hpp
, though + it is not exactly the same aspromote_args
+ either.common_type<T1, T2>::type
+ simply represents the result of some operation onT1
+ andT2
, and defaults to the + type obtained by puttingT1
+ andT2
into a conditional statement.@@ -346,7 +331,7 @@