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