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

Detailed Description

Outline

Purpose

Provide a meta-function for adding top-level cv-qualifiers.

Classes

See also
bslmf_removecv

Description

This component defines a meta-function, bsl::add_cv and declares an bsl::add_cv_t alias to the return type of the bsl::add_cv, that may be used to add a top-level const-qualifier and a top-level volatile-qualifier to a type if it is not a reference type, nor a function type, nor already const-qualified and volatile-qualified at the top-level.

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

Usage

In this section we show intended use of this component.

Example 1: Adding a const-Qualifier and a volatile-Qualifier to a Type

Suppose that we want to add a const-qualifier and a volatile-qualifier to a particular type.

First, we create two typedefs – a const-qualified and volatile-qualified type (MyCvType) and the same type without the cv-qualifiers (MyType):

typedef int MyType;
typedef const volatile int MyCvType;

Now, we add a const-qualifier and a volatile-qualifier to MyType using bsl::add_cv and verify that the resulting type is the same as MyCvType:

assert(true == (bsl::is_same<bsl::add_cv<MyType>::type, MyCvType>::value));
add_const< typenameadd_volatile< t_TYPE >::type >::type type
Definition bslmf_addcv.h:130
Definition bslmf_issame.h:146

Finally, if the current compiler supports alias templates C++11 feature, we add a const-qualifier and a volatile-qualifier to MyType using bsl::add_cv_t and verify that the resulting type is the same as MyCvType:

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

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