Quick Links:

bal | bbl | bdl | bsl

Classes

Component bslmf_addlvaluereference
[Package bslmf]

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

Classes

struct  bsl::add_lvalue_reference< t_TYPE >
struct  bsl::add_lvalue_reference< t_TYPE & >
struct  bsl::add_lvalue_reference< void >
struct  bsl::add_lvalue_reference< void const >
struct  bsl::add_lvalue_reference< void volatile >
struct  bsl::add_lvalue_reference< void const volatile >

Detailed Description

Outline
Purpose:
Provide a compile-time type transformation to lvalue reference.
Classes:
bsl::add_lvalue_reference standard meta-function for type transformation
bsl::add_lvalue_reference_t alias to the return type of the meta-function
See also:
Component bslmf_addrvaluereference, Component bslmf_removereference
Description:
This component defines a meta-function, bsl::add_lvalue_reference, that may be used to transform a type to its lvalue reference type. An lvalue, as defined in C++11 standard [basic.lval], is an expression that designates a function or an object.
bsl::add_lvalue_reference and bsl::add_lvalue_reference_t meet the requirements of the add_lvalue_reference template defined in the C++11 standard [meta.trans.ref].
Usage:
In this section we show intended use of this component.
Example 1: Transforming Types to Lvalue Reference Types:
Suppose that we want to transform a set of types to their lvalue reference types.
Now, we instantiate the bsl::add_lvalue_reference template for each of these types, and use the bsl::is_same meta-function to assert the type static data member of each instantiation:
  assert(true ==
        (bsl::is_same<bsl::add_lvalue_reference<int>::type,   int&>::value));
  assert(false ==
        (bsl::is_same<bsl::add_lvalue_reference<int>::type,   int >::value));
  assert(true ==
        (bsl::is_same<bsl::add_lvalue_reference<int&>::type,  int&>::value));
#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
  assert(true ==
        (bsl::is_same<bsl::add_lvalue_reference<int&&>::type, int&>::value));
#endif
Finally, if the current compiler supports alias templates C++11 feature, we instantiate the bsl::add_lvalue_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_lvalue_reference_t<int>,   int& >::value));
  assert(false ==
          (bsl::is_same<bsl::add_lvalue_reference_t<int>,   int  >::value));
  assert(true  ==
          (bsl::is_same<bsl::add_lvalue_reference_t<int&>,  int& >::value));
#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
  assert(true ==
          (bsl::is_same<bsl::add_lvalue_reference_t<int&&>, int&&>::value));
#endif
#endif
Note, that the rvalue reference used above is a feature introduced in the C++11 standard and may not be supported by all compilers.
Also note that the bsl::add_lvalue_reference_t avoids the ::type suffix and typename prefix when we want to use the result of bsl::add_lvalue_reference meta-function in templates.