BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmf_removepointer.h
Go to the documentation of this file.
1/// @file bslmf_removepointer.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_removepointer.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_REMOVEPOINTER
9#define INCLUDED_BSLMF_REMOVEPOINTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_removepointer bslmf_removepointer
15/// @brief Provide a meta-function to transform pointer type to referent type.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_removepointer
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_removepointer-purpose"> Purpose</a>
25/// * <a href="#bslmf_removepointer-classes"> Classes </a>
26/// * <a href="#bslmf_removepointer-description"> Description </a>
27/// * <a href="#bslmf_removepointer-usage"> Usage </a>
28/// * <a href="#bslmf_removepointer-example-1-get-the-type-pointed-to-by-a-pointer-type"> Example 1: Get the Type Pointed to by a Pointer Type </a>
29///
30/// # Purpose {#bslmf_removepointer-purpose}
31/// Provide a meta-function to transform pointer type to referent type.
32///
33/// # Classes {#bslmf_removepointer-classes}
34///
35/// - bsl::remove_pointer: transform a pointer type to its referent pointer
36/// - bsl::remove_pointer_t: alias to the return type of the meta-function
37///
38/// @see bslmf_addpointer
39///
40/// # Description {#bslmf_removepointer-description}
41/// This component defines a meta-function, `bsl::remove_pointer`,
42/// that may be used to obtain the type pointed to by a pointer type.
43///
44/// `bsl::remove_pointer` and `bsl::remove_pointer_t` meet the requirements of
45/// the @ref remove_pointer template defined in the C++11 standard
46/// [meta.trans.ptr].
47///
48/// ## Usage {#bslmf_removepointer-usage}
49///
50///
51/// In this section we show intended use of this component.
52///
53/// ### Example 1: Get the Type Pointed to by a Pointer Type {#bslmf_removepointer-example-1-get-the-type-pointed-to-by-a-pointer-type}
54///
55///
56/// Suppose that we want to get the type pointed to by a pointer type.
57///
58/// First, we create two `typedef`s -- a pointer type (`MyPtrType`) and the type
59/// pointed to by the pointer type (`MyType`):
60/// @code
61/// typedef int MyType;
62/// typedef int *MyPtrType;
63/// @endcode
64/// Now, we get the type pointed to by `MyPtrType` using `bsl::remove_pointer`
65/// and verify that the resulting type is the same as `MyType`:
66/// @code
67/// assert((bsl::is_same<bsl::remove_pointer<MyPtrType>::type,
68/// MyType>::value));
69/// @endcode
70/// Finally, if the current compiler supports alias templates C++11 feature, we
71/// get the type pointed to by `MyPtrType` using `bsl::remove_pointer_t` and
72/// verify that the resulting type is the same as `MyType`:
73/// @code
74/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
75/// assert((bsl::is_same<bsl::remove_pointer_t<MyPtrType>, MyType>::value));
76/// #endif
77/// @endcode
78/// Note, that the `bsl::remove_pointer_t` avoids the `::type` suffix and
79/// `typename` prefix when we want to use the result of the
80/// `bsl::remove_pointer` meta-function in templates.
81/// @}
82/** @} */
83/** @} */
84
85/** @addtogroup bsl
86 * @{
87 */
88/** @addtogroup bslmf
89 * @{
90 */
91/** @addtogroup bslmf_removepointer
92 * @{
93 */
94
95#include <bslscm_version.h>
96
98
100#include <bsls_platform.h>
101
102#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
103 // Permit reliance on transitive includes within robo.
104#include <bslmf_removecvq.h>
105#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
106
107
108namespace bslmf {
109
110 // ========================
111 // struct RemovePointer_Imp
112 // ========================
113
114/// This `struct` template provides an alias `Type` that refers to the type
115/// pointed to by the (template parameter) `t_TYPE` if `t_TYPE` is a
116/// (non-cv-qualified) pointer type; otherwise, `Type` refers to `t_TYPE`.
117/// This generic default template's `Type` always refers to `t_TYPE`. A
118/// template specialization (below) handles the case where `t_TYPE` is a
119/// pointer type.
120///
121/// See @ref bslmf_removepointer
122template <class t_TYPE>
124
125 // PUBLIC TYPES
126
127 /// This `typedef` is an alias to the (template parameter) `t_TYPE`.
128 typedef t_TYPE Type;
129};
130
131 // ==================================
132 // struct RemovePointer_Imp<t_TYPE *>
133 // ==================================
134
135/// This partial specialization of `RemovePointer_Imp`, for when the
136/// (template parameter) `t_TYPE` is a pointer type, provides an alias
137/// `Type` that refers to the type pointed to by `t_TYPE`.
138template <class t_TYPE>
139struct RemovePointer_Imp<t_TYPE *> {
140
141 // PUBLIC TYPES
142
143 /// This `typedef` is an alias to the type pointed to by the (template
144 /// parameter) `t_TYPE`.
145 typedef t_TYPE Type;
146};
147
148/// This partial specialization of `RemovePointer_Imp`, for when the
149/// (template parameter) `t_TYPE` is a `const`-qualified pointer type,
150/// provides an alias `Type` that refers to the type pointed to by `t_TYPE`.
151///
152/// \note Note that this is specifically for `const`-qualified pointers, and not
153/// for pointers-to-`const`-type.
154template <class t_TYPE>
155struct RemovePointer_Imp<t_TYPE *const> {
156
157 // PUBLIC TYPES
158
159 /// This `typedef` is an alias to the type pointed to by the (template
160 /// parameter) `t_TYPE`.
161 typedef t_TYPE Type;
162};
163
164/// This partial specialization of `RemovePointer_Imp`, for when the
165/// (template parameter) `t_TYPE` is a `volatile`-qualified pointer type,
166/// provides an alias `Type` that refers to the type pointed to by `t_TYPE`.
167///
168/// \note Note that this is specifically for `volatile`-qualified pointers, and
169/// not for pointers-to-`volatile`-type.
170template <class t_TYPE>
171struct RemovePointer_Imp<t_TYPE *volatile> {
172
173 // PUBLIC TYPES
174
175 /// This `typedef` is an alias to the type pointed to by the (template
176 /// parameter) `t_TYPE`.
177 typedef t_TYPE Type;
178};
179
180/// This partial specialization of `RemovePointer_Imp`, for when the
181/// (template parameter) `t_TYPE` is a `const volatile`-qualified pointer
182/// type, provides an alias `Type` that refers to the type pointed to by `t_TYPE`.
183///
184/// \note Note that this is specifically for `const volatile`-qualified
185/// pointers, and not for pointers-to-`const volatile`-type.
186template <class t_TYPE>
187struct RemovePointer_Imp<t_TYPE *const volatile> {
188
189 // PUBLIC TYPES
190
191 /// This `typedef` is an alias to the type pointed to by the (template
192 /// parameter) `t_TYPE`.
193 typedef t_TYPE Type;
194};
195
196#if defined(BSLS_PLATFORM_CMP_IBM)
197template <class t_TYPE, bool isFunctionPtr>
198struct RemovePointer_Aix : RemovePointer_Imp<t_TYPE> {
199 // The implementation of the 'RemovePointer_Imp' for the AIX xlC 11
200 // compiler uses the generic mechanism for non-function types, but see
201 // below for a specialization for pointer-to-function types.
202};
203
204template <class t_TYPE>
205struct RemovePointer_Aix<t_TYPE, true> {
206 // The implementation of the 'RemovePointer_Imp' for the AIX xlC 11
207 // compiler when 't_TYPE' is a pointer-to-function. xlC 11 has a bug
208 // specializing on 't_TYPE*' where 't_TYPE' is was deduced from the address
209 // of a function with default arguments. To workaround the bug, this
210 // specialization uses 'FunctionPointerTraits' to obtain the function type
211 // by somewhat more complicated means.
212
213 typedef typename FunctionPointerTraits<t_TYPE>::FuncType Type;
214};
215#endif
216
217#if defined(BSLS_PLATFORM_CMP_MSVC)
218template <class t_TYPE, bool isFunctionPtr = IsFunctionPointer<t_TYPE>::value>
219struct RemovePointer_Msvc : RemovePointer_Imp<t_TYPE> {
220 // The implementation of the 'RemovePointer_Imp' for the Microsoft Visual
221 // C++ compiler which has a bug matching a 'T * const' template parameter
222 // with a cv-qualified function pointer type. To workaround the bug, we
223 // provide additional partial specializations predicated on 't_TYPE' being
224 // a function pointer type to first strip the cv-qualifier, and then
225 // delegate to the regular 'RemovePointer_Imp'. This yields the correct
226 // result withough accidentally stripping the cv-qualifier from non-pointer
227 // types.
228};
229
230template <class t_TYPE>
231struct RemovePointer_Msvc<t_TYPE const, true> : RemovePointer_Imp<t_TYPE> {
232};
233
234template <class t_TYPE>
235struct RemovePointer_Msvc<t_TYPE volatile, true> : RemovePointer_Imp<t_TYPE> {
236};
237
238template <class t_TYPE>
239struct RemovePointer_Msvc<t_TYPE const volatile, true>
240: RemovePointer_Imp<t_TYPE> {
241};
242#endif
243
244} // close package namespace
245
246
247namespace bsl {
248
249 // =====================
250 // struct remove_pointer
251 // =====================
252
253/// This `struct` template implements the @ref remove_pointer meta-function
254/// defined in the C++11 standard [meta.trans.ptr], providing an alias,
255/// `type`, that returns the result. If the (template parameter) `t_TYPE`
256/// is a (possibly cv-qualified) pointer type, then `type` is an alias to
257/// the type pointed to by `t_TYPE`; otherwise, `type` is an alias to
258/// `t_TYPE`.
259///
260/// See @ref bslmf_removepointer
261template <class t_TYPE>
263
264#if defined(BSLS_PLATFORM_CMP_IBM)
265 typedef typename BloombergLP::bslmf::RemovePointer_Aix<
266 t_TYPE,
267 BloombergLP::bslmf::IsFunctionPointer<t_TYPE>::value>::Type type;
268#elif defined(BSLS_PLATFORM_CMP_MSVC)
269 typedef typename BloombergLP::bslmf::RemovePointer_Msvc<t_TYPE>::Type type;
270#else
271 /// This `typedef` is an alias to the type pointed to by the (template
272 /// parameter) `t_TYPE` if `t_TYPE` is a (possibly cv-qualified) pointer
273 /// type; otherwise, `type` is an alias to `t_TYPE`.
274 typedef typename BloombergLP::bslmf::RemovePointer_Imp<t_TYPE>::Type type;
275
276#endif
277};
278
279#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
280
281// ALIASES
282
283/// @ref remove_pointer_t is an alias to the return type of the
284/// `bsl::remove_pointer` meta-function. Note, that the @ref remove_pointer_t
285/// avoids the `::type` suffix and `typename` prefix when we want to use the
286/// result of the meta-function in templates.
287template <class t_TYPE>
288using remove_pointer_t = typename remove_pointer<t_TYPE>::type;
289
290#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
291
292} // close namespace bsl
293
294#endif
295
296// ----------------------------------------------------------------------------
297// Copyright 2013 Bloomberg Finance L.P.
298//
299// Licensed under the Apache License, Version 2.0 (the "License");
300// you may not use this file except in compliance with the License.
301// You may obtain a copy of the License at
302//
303// http://www.apache.org/licenses/LICENSE-2.0
304//
305// Unless required by applicable law or agreed to in writing, software
306// distributed under the License is distributed on an "AS IS" BASIS,
307// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
308// See the License for the specific language governing permissions and
309// limitations under the License.
310// ----------------------------- END-OF-FILE ----------------------------------
311
312/** @} */
313/** @} */
314/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlat_valuetypefunctions.h:939
Definition bdlbb_blob.h:579
Definition bslmf_removepointer.h:262
BloombergLP::bslmf::RemovePointer_Imp< t_TYPE >::Type type
Definition bslmf_removepointer.h:274
t_TYPE Type
Definition bslmf_removepointer.h:145
t_TYPE Type
Definition bslmf_removepointer.h:161
t_TYPE Type
Definition bslmf_removepointer.h:193
t_TYPE Type
Definition bslmf_removepointer.h:177
Definition bslmf_removepointer.h:123
t_TYPE Type
This typedef is an alias to the (template parameter) t_TYPE.
Definition bslmf_removepointer.h:128