Quick Links:

bal | bbl | bdl | bsl

Classes

Component bslmf_removereference
[Package bslmf]

Provide a meta-function for stripping reference-ness from types. More...

Classes

struct  bsl::remove_reference< t_TYPE >
struct  bsl::remove_reference< t_TYPE & >

Detailed Description

Outline
Purpose:
Provide a meta-function for stripping reference-ness from types.
Classes:
bsl::remove_reference standard meta-function for stripping reference-ness
bsl::remove_reference_t alias to the return type of the meta-function
bslmf::RemoveReference meta-function for stripping reference-ness
See also:
Component bslmf_addreference
Description:
This component defines two meta-functions, bsl::remove_reference and BloombergLP::bslmf::RemoveReference, both of which may be used to strip reference-ness (including both lvalue and rvalue reference-ness, if the latter is supported by the compiler) from a type.
bsl::remove_reference meets the requirements of the remove_reference template defined in the C++11 standard [meta.trans.ref], while bslmf::RemoveReference was devised before remove_reference was standardized.
The two meta-functions are functionally equivalent. The major difference between them is that the result for bsl::remove_reference is indicated by the class member type, while the result for bslmf::RemoveReference is indicated by the class member Type.
Note that bsl::remove_reference should be preferred over bslmf::RemoveReference, and in general, should be used by new components.
Usage:
In this section we show intended use of this component.
Example 1: Remove Reference-ness of Types:
Suppose that we want to remove the reference-ness of a set of types.
Now, remove the reference-ness of a set of types using bsl::remove_reference and verify that the returned type has any reference-ness removed:
  assert(true  ==
            (bsl::is_same<bsl::remove_reference<int& >::type, int >::value));
  assert(false ==
            (bsl::is_same<bsl::remove_reference<int& >::type, int&>::value));
  assert(true  ==
            (bsl::is_same<bsl::remove_reference<int  >::type, int >::value));
#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
  assert(true ==
            (bsl::is_same<bsl::remove_reference<int&&>::type, int >::value));
#endif
Finally, if the current compiler supports alias templates C++11 feature, we remove reference-ness from a set of types using bsl::remove_reference_t and verify that the resulting type has any reference-ness removed:
#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
  assert(true  ==
            (bsl::is_same<bsl::remove_reference_t<int& >, int >::value));
  assert(false ==
            (bsl::is_same<bsl::remove_reference_t<int& >, int&>::value));
  assert(true  ==
            (bsl::is_same<bsl::remove_reference_t<int  >, int >::value));
#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
  assert(true ==
            (bsl::is_same<bsl::remove_reference_t<int&&>, int >::value));
#endif
#endif
Note that rvalue reference is a feature introduced in the C++11 standard and may not be supported by all compilers.
Also note, that the bsl::remove_reference_t avoids the ::type suffix and typename prefix when we want to use the result of the bsl::remove_reference meta-function in templates.