Quick Links:

bal | bbl | bdl | bsl

Component bslmf_addrvaluereference
[Package bslmf]

Provide a compile-time type transformation to rvalue reference. More...

Outline
Purpose:
Provide a compile-time type transformation to rvalue reference.
Classes:
bsl::add_rvalue_reference standard meta-function for transforming types
bsl::add_rvalue_reference_t alias to the return type of the meta-function
See also:
Component bslmf_integralconstant, Component bslmf_addlvaluereference
Description:
This component defines a meta-function, bsl::add_rvalue_reference, that may be used to transform a type to its rvalue reference type.
bsl::add_rvalue_reference and bsl::add_rvalue_reference_t meet the requirements of the add_rvalue_reference template defined in the C++11 standard [meta.trans.ref].
Usage:
In this section we show intended use of this component.
Example 1: Transform to Rvalue Reference Types:
Suppose that we want to transform some types to rvalue reference types.
Now, for a set of types, we transform each type to the corresponding rvalue reference of that type using bsl::add_rvalue_reference and verify the result:
#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
  assert(true  ==
       (bsl::is_same<bsl::add_rvalue_reference<int>::type,   int&&>::value));
  assert(false ==
       (bsl::is_same<bsl::add_rvalue_reference<int>::type,   int  >::value));
  assert(true  ==
       (bsl::is_same<bsl::add_rvalue_reference<int&>::type,  int& >::value));
  assert(true  ==
       (bsl::is_same<bsl::add_rvalue_reference<int&&>::type, int&&>::value));
Finally, if the current compiler supports alias templates C++11 feature, we instantiate the bsl::add_rvalue_reference_t template for the same set of types, and use the bsl::is_same meta-function to assert the resultant type of each instantiation:
#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
  assert(true  ==
          (bsl::is_same<bsl::add_rvalue_reference_t<int>,   int&&>::value));
  assert(false ==
          (bsl::is_same<bsl::add_rvalue_reference_t<int>,   int  >::value));
  assert(true  ==
          (bsl::is_same<bsl::add_rvalue_reference_t<int&>,  int& >::value));
  assert(true ==
          (bsl::is_same<bsl::add_rvalue_reference_t<int&&>, int&&>::value));
#endif
#endif
Note that rvalue reference was introduced in C++11 and may not be supported by all compilers. Note also that according to reference collapsing semantics [8.3.2], add_rvalue_reference does not transform t_TYPE to rvalue reference type if t_TYPE is an lvalue reference type.
Also note that the bsl::add_rvalue_reference_t avoids the ::type suffix and typename prefix when we want to use the result of bsl::add_rvalue_reference meta-function in templates.