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

Detailed Description

Outline

Purpose

Provide a meta-function for removing top-level const-qualifier.

Classes

See also
bslmf_addconst

Description

This component defines a meta-function, bsl::remove_const and declares an bsl::remove_const_t alias to the return type of the bsl::remove_const, that may be used to remove any top-level const-qualifier from a type.

bsl::remove_const and bsl::remove_const_t meet the requirements of the remove_const template defined in the C++11 standard [meta.trans.cv].

Usage

In this section we show intended use of this component.

Example 1: Removing the const-Qualifier of a Type

Suppose that we want to remove any top-level const-qualifier from a particular type.

First, we create two typedefs – a const-qualified type (MyConstType) and the same type without the const-qualifier (MyType):

typedef int MyType;
typedef const int MyConstType;

Now, we remove the const-qualifier from MyConstType using bsl::remove_const and verify that the resulting type is the same as MyType:

assert(true ==
Definition bslmf_issame.h:146
t_TYPE type
This typedef is an alias to the (template parameter) t_TYPE.
Definition bslmf_removeconst.h:161

Finally, if the current compiler supports alias templates C++11 feature, we remove a const-qualifier from MyConstType using bsl::remove_const_t and verify that the resulting type is the same as MyType:

#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
assert(true ==
(bsl::is_same<bsl::remove_const_t<MyConstType>, MyType>::value));
#endif

Note, that the bsl::remove_const_t avoids the ::type suffix and typename prefix when we want to use the result of the bsl::remove_const meta-function in templates.