Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bslmf_addvolatile
[Package bslmf]

Provide a meta-function for adding a volatile-qualifier. More...

Namespaces

namespace  bslmf
namespace  bsl

Detailed Description

Outline
Purpose:
Provide a meta-function for adding a volatile-qualifier.
Classes:
bsl::add_volatile meta-function for adding top-level volatile-qualifier
bsl::add_volatile_t alias to the return type of the bsl::add_volatile
See also:
Component bslmf_removevolatile
Description:
This component defines a meta-function, bsl::add_volatile and declares an bsl::add_volatile_t alias to the return type of the bsl::add_volatile, that may be used to add a top-level volatile-qualifier to a type if it is not a reference type, nor a function type, nor already volatile-qualified at the top-level.
bsl::add_volatile and bsl::add_volatile_t meet the requirements of the add_volatile 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 volatile-Qualifier to a Type:
Suppose that we want to add a volatile-qualifier to a particular type.
First, we create two typedefs -- a volatile-qualified type (MyVolatileType) and the same type without the volatile-qualifier (MyType):
  typedef int          MyType;
  typedef volatile int MyVolatileType;
Now, we add a volatile-qualifier to MyType using bsl::add_volatile and verify that the resulting type is the same as MyVolatileType:
  assert(true ==
     (bsl::is_same<bsl::add_volatile<MyType>::type, MyVolatileType>::value));
Finally, if the current compiler supports alias templates C++11 feature, we add a volatile-qualifier to MyType using bsl::add_volatile_t and verify that the resulting type is the same as MyVolatileType:
#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
  assert(true ==
         (bsl::is_same<bsl::add_volatile_t<MyType>, MyVolatileType>::value));
#endif
Note, that the bsl::add_volatile_t avoids the ::type suffix and typename prefix when we want to use the result of the bsl::add_volatile meta-function in templates.