BDE 4.14.0 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.
120template <class t_TYPE>
122
123 // PUBLIC TYPES
124
125 /// This `typedef` is an alias to the (template parameter) `t_TYPE`.
126 typedef t_TYPE Type;
127};
128
129 // ==================================
130 // struct RemovePointer_Imp<t_TYPE *>
131 // ==================================
132
133/// This partial specialization of `RemovePointer_Imp`, for when the
134/// (template parameter) `t_TYPE` is a pointer type, provides an alias
135/// `Type` that refers to the type pointed to by `t_TYPE`.
136template <class t_TYPE>
137struct RemovePointer_Imp<t_TYPE *> {
138
139 // PUBLIC TYPES
140
141 /// This `typedef` is an alias to the type pointed to by the (template
142 /// parameter) `t_TYPE`.
143 typedef t_TYPE Type;
144};
145
146/// This partial specialization of `RemovePointer_Imp`, for when the
147/// (template parameter) `t_TYPE` is a `const`-qualified pointer type,
148/// provides an alias `Type` that refers to the type pointed to by `t_TYPE`.
149/// Note that this is specifically for `const`-qualified pointers, and not
150/// for pointers-to-`const`-type.
151template <class t_TYPE>
152struct RemovePointer_Imp<t_TYPE *const> {
153
154 // PUBLIC TYPES
155
156 /// This `typedef` is an alias to the type pointed to by the (template
157 /// parameter) `t_TYPE`.
158 typedef t_TYPE Type;
159};
160
161/// This partial specialization of `RemovePointer_Imp`, for when the
162/// (template parameter) `t_TYPE` is a `volatile`-qualified pointer type,
163/// provides an alias `Type` that refers to the type pointed to by `t_TYPE`.
164/// Note that this is specifically for `volatile`-qualified pointers, and
165/// not for pointers-to-`volatile`-type.
166template <class t_TYPE>
167struct RemovePointer_Imp<t_TYPE *volatile> {
168
169 // PUBLIC TYPES
170
171 /// This `typedef` is an alias to the type pointed to by the (template
172 /// parameter) `t_TYPE`.
173 typedef t_TYPE Type;
174};
175
176/// This partial specialization of `RemovePointer_Imp`, for when the
177/// (template parameter) `t_TYPE` is a `const volatile`-qualified pointer
178/// type, provides an alias `Type` that refers to the type pointed to by
179/// `t_TYPE`. Note that this is specifically for `const volatile`-qualified
180/// pointers, and not for pointers-to-`const volatile`-type.
181template <class t_TYPE>
182struct RemovePointer_Imp<t_TYPE *const volatile> {
183
184 // PUBLIC TYPES
185
186 /// This `typedef` is an alias to the type pointed to by the (template
187 /// parameter) `t_TYPE`.
188 typedef t_TYPE Type;
189};
190
191#if defined(BSLS_PLATFORM_CMP_IBM)
192template <class t_TYPE, bool isFunctionPtr>
193struct RemovePointer_Aix : RemovePointer_Imp<t_TYPE> {
194 // The implementation of the 'RemovePointer_Imp' for the AIX xlC 11
195 // compiler uses the generic mechanism for non-function types, but see
196 // below for a specialization for pointer-to-function types.
197};
198
199template <class t_TYPE>
200struct RemovePointer_Aix<t_TYPE, true> {
201 // The implementation of the 'RemovePointer_Imp' for the AIX xlC 11
202 // compiler when 't_TYPE' is a pointer-to-function. xlC 11 has a bug
203 // specializing on 't_TYPE*' where 't_TYPE' is was deduced from the address
204 // of a function with default arguments. To workaround the bug, this
205 // specialization uses 'FunctionPointerTraits' to obtain the function type
206 // by somewhat more complicated means.
207
208 typedef typename FunctionPointerTraits<t_TYPE>::FuncType Type;
209};
210#endif
211
212#if defined(BSLS_PLATFORM_CMP_MSVC)
213template <class t_TYPE, bool isFunctionPtr = IsFunctionPointer<t_TYPE>::value>
214struct RemovePointer_Msvc : RemovePointer_Imp<t_TYPE> {
215 // The implementation of the 'RemovePointer_Imp' for the Microsoft Visual
216 // C++ compiler which has a bug matching a 'T * const' template parameter
217 // with a cv-qualified function pointer type. To workaround the bug, we
218 // provide additional partial specializations predicated on 't_TYPE' being
219 // a function pointer type to first strip the cv-qualifier, and then
220 // delegate to the regular 'RemovePointer_Imp'. This yields the correct
221 // result withough accidentally stripping the cv-qualifier from non-pointer
222 // types.
223};
224
225template <class t_TYPE>
226struct RemovePointer_Msvc<t_TYPE const, true> : RemovePointer_Imp<t_TYPE> {
227};
228
229template <class t_TYPE>
230struct RemovePointer_Msvc<t_TYPE volatile, true> : RemovePointer_Imp<t_TYPE> {
231};
232
233template <class t_TYPE>
234struct RemovePointer_Msvc<t_TYPE const volatile, true>
235: RemovePointer_Imp<t_TYPE> {
236};
237#endif
238
239} // close package namespace
240
241
242namespace bsl {
243
244 // =====================
245 // struct remove_pointer
246 // =====================
247
248/// This `struct` template implements the @ref remove_pointer meta-function
249/// defined in the C++11 standard [meta.trans.ptr], providing an alias,
250/// `type`, that returns the result. If the (template parameter) `t_TYPE`
251/// is a (possibly cv-qualified) pointer type, then `type` is an alias to
252/// the type pointed to by `t_TYPE`; otherwise, `type` is an alias to
253/// `t_TYPE`.
254template <class t_TYPE>
256
257#if defined(BSLS_PLATFORM_CMP_IBM)
258 typedef typename BloombergLP::bslmf::RemovePointer_Aix<
259 t_TYPE,
260 BloombergLP::bslmf::IsFunctionPointer<t_TYPE>::value>::Type type;
261#elif defined(BSLS_PLATFORM_CMP_MSVC)
262 typedef typename BloombergLP::bslmf::RemovePointer_Msvc<t_TYPE>::Type type;
263#else
264 /// This `typedef` is an alias to the type pointed to by the (template
265 /// parameter) `t_TYPE` if `t_TYPE` is a (possibly cv-qualified) pointer
266 /// type; otherwise, `type` is an alias to `t_TYPE`.
267 typedef typename BloombergLP::bslmf::RemovePointer_Imp<t_TYPE>::Type type;
268
269#endif
270};
271
272#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
273
274// ALIASES
275
276/// `remove_pointer_t` is an alias to the return type of the
277/// `bsl::remove_pointer` meta-function. Note, that the `remove_pointer_t`
278/// avoids the `::type` suffix and `typename` prefix when we want to use the
279/// result of the meta-function in templates.
280template <class t_TYPE>
281using remove_pointer_t = typename remove_pointer<t_TYPE>::type;
282
283#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
284
285} // close namespace bsl
286
287#endif
288
289// ----------------------------------------------------------------------------
290// Copyright 2013 Bloomberg Finance L.P.
291//
292// Licensed under the Apache License, Version 2.0 (the "License");
293// you may not use this file except in compliance with the License.
294// You may obtain a copy of the License at
295//
296// http://www.apache.org/licenses/LICENSE-2.0
297//
298// Unless required by applicable law or agreed to in writing, software
299// distributed under the License is distributed on an "AS IS" BASIS,
300// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
301// See the License for the specific language governing permissions and
302// limitations under the License.
303// ----------------------------- END-OF-FILE ----------------------------------
304
305/** @} */
306/** @} */
307/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
Definition bdlbb_blob.h:576
Definition bslmf_removepointer.h:255
BloombergLP::bslmf::RemovePointer_Imp< t_TYPE >::Type type
Definition bslmf_removepointer.h:267
t_TYPE Type
Definition bslmf_removepointer.h:143
t_TYPE Type
Definition bslmf_removepointer.h:158
t_TYPE Type
Definition bslmf_removepointer.h:188
t_TYPE Type
Definition bslmf_removepointer.h:173
Definition bslmf_removepointer.h:121
t_TYPE Type
This typedef is an alias to the (template parameter) t_TYPE.
Definition bslmf_removepointer.h:126