BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_addcv.h
Go to the documentation of this file.
1/// @file bslmf_addcv.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_addcv.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ADDCV
9#define INCLUDED_BSLMF_ADDCV
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_addcv bslmf_addcv
15/// @brief Provide a meta-function for adding top-level cv-qualifiers.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_addcv
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_addcv-purpose"> Purpose</a>
25/// * <a href="#bslmf_addcv-classes"> Classes </a>
26/// * <a href="#bslmf_addcv-description"> Description </a>
27/// * <a href="#bslmf_addcv-usage"> Usage </a>
28/// * <a href="#bslmf_addcv-example-1-adding-a-const-qualifier-and-a-volatile-qualifier-to-a-type"> Example 1: Adding a const-Qualifier and a volatile-Qualifier to a Type </a>
29///
30/// # Purpose {#bslmf_addcv-purpose}
31/// Provide a meta-function for adding top-level cv-qualifiers.
32///
33/// # Classes {#bslmf_addcv-classes}
34///
35/// - bsl::add_cv: meta-function for adding top-level cv-qualifiers
36/// - bsl::add_cv_t: alias to the return type of the `bsl::add_cv` meta-function
37///
38/// @see bslmf_removecv
39///
40/// # Description {#bslmf_addcv-description}
41/// This component defines a meta-function, `bsl::add_cv` and
42/// declares an `bsl::add_cv_t` alias to the return type of the `bsl::add_cv`,
43/// that may be used to add a top-level `const`-qualifier and a top-level
44/// `volatile`-qualifier to a type if it is not a reference type, nor a function
45/// type, nor already `const`-qualified and `volatile`-qualified at the
46/// top-level.
47///
48/// `bsl::add_cv` and `bsl::add_cv_t` meet the requirements of the `add_cv`
49/// template defined in the C++11 standard [meta.trans.cv].
50///
51/// ## Usage {#bslmf_addcv-usage}
52///
53///
54/// In this section we show intended use of this component.
55///
56/// ### Example 1: Adding a const-Qualifier and a volatile-Qualifier to a Type {#bslmf_addcv-example-1-adding-a-const-qualifier-and-a-volatile-qualifier-to-a-type}
57///
58///
59/// Suppose that we want to add a `const`-qualifier and a `volatile`-qualifier
60/// to a particular type.
61///
62/// First, we create two `typedef`s -- a `const`-qualified and
63/// `volatile`-qualified type (`MyCvType`) and the same type without the
64/// cv-qualifiers (`MyType`):
65/// @code
66/// typedef int MyType;
67/// typedef const volatile int MyCvType;
68/// @endcode
69/// Now, we add a `const`-qualifier and a `volatile`-qualifier to `MyType` using
70/// `bsl::add_cv` and verify that the resulting type is the same as `MyCvType`:
71/// @code
72/// assert(true == (bsl::is_same<bsl::add_cv<MyType>::type, MyCvType>::value));
73/// @endcode
74/// Finally, if the current compiler supports alias templates C++11 feature, we
75/// add a `const`-qualifier and a `volatile`-qualifier to `MyType` using
76/// `bsl::add_cv_t` and verify that the resulting type is the same as
77/// `MyCvType`:
78/// @code
79/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
80/// assert(true == (bsl::is_same<bsl::add_cv_t<MyType>, MyCvType>::value));
81/// #endif
82/// @endcode
83/// Note, that the `bsl::add_cv_t` avoids the `::type` suffix and `typename`
84/// prefix when we want to use the result of the `bsl::add_cv` meta-function in
85/// templates.
86/// @}
87/** @} */
88/** @} */
89
90/** @addtogroup bsl
91 * @{
92 */
93/** @addtogroup bslmf
94 * @{
95 */
96/** @addtogroup bslmf_addcv
97 * @{
98 */
99
100#include <bslscm_version.h>
101
102#include <bslmf_addconst.h>
103#include <bslmf_addvolatile.h>
104
106
107namespace bsl {
108
109 // =============
110 // struct add_cv
111 // =============
112
113/// This `struct` template implements the `add_cv` meta-function defined in
114/// the C++11 standard [meta.trans.cv], providing an alias, `type`, that
115/// returns the result. If the (template parameter) `t_TYPE` is not a
116/// reference type, nor a function type, nor already `const`-qualified and
117/// `volatile`-qualified at the top-level, then `type` is an alias to
118/// `t_TYPE` with a top-level `const`-qualifier and a `volatile`-qualifier
119/// added; otherwise, `type` is an alias to `t_TYPE`.
120template <class t_TYPE>
121struct add_cv {
122
123 // PUBLIC TYPES
124
125 /// This `typedef` is an alias to the (template parameter) `t_TYPE` with
126 /// a top-level `const`-qualifier and `volatile`-qualifier added if
127 /// `t_TYPE` is not a reference type, nor a function type, nor already
128 /// `const`-qualified and `volatile`-qualified at the top-level;
129 /// otherwise, `type` is an alias to `t_TYPE`.
131};
132
133#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
134
135// ALIASES
136
137/// `add_cv_t` is an alias to the return type of the `bsl::add_cv`
138/// meta-function. Note, that the `add_cv_t` avoids the `::type` suffix and
139/// `typename` prefix when we want to use the result of the `bsl::add_cv` in
140/// templates.
141template <class t_TYPE>
142using add_cv_t = typename add_cv<t_TYPE>::type;
143#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
144
145} // close namespace bsl
146
147#endif
148
149// ----------------------------------------------------------------------------
150// Copyright 2013 Bloomberg Finance L.P.
151//
152// Licensed under the Apache License, Version 2.0 (the "License");
153// you may not use this file except in compliance with the License.
154// You may obtain a copy of the License at
155//
156// http://www.apache.org/licenses/LICENSE-2.0
157//
158// Unless required by applicable law or agreed to in writing, software
159// distributed under the License is distributed on an "AS IS" BASIS,
160// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
161// See the License for the specific language governing permissions and
162// limitations under the License.
163// ----------------------------- END-OF-FILE ----------------------------------
164
165/** @} */
166/** @} */
167/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
Definition bslmf_addconst.h:161
Definition bslmf_addcv.h:121
add_const< typenameadd_volatile< t_TYPE >::type >::type type
Definition bslmf_addcv.h:130