BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_removereference

Macros

#define bslmf_RemoveReference   bslmf::RemoveReference
 This alias is defined for backward compatibility.
 

Detailed Description

Outline

Purpose

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

Classes

See also
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
Definition bslmf_issame.h:146

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.

Macro Definition Documentation

◆ bslmf_RemoveReference

#define bslmf_RemoveReference   bslmf::RemoveReference