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