BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_arraytopointer.h
Go to the documentation of this file.
1/// @file bslmf_arraytopointer.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_arraytopointer.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ARRAYTOPOINTER
9#define INCLUDED_BSLMF_ARRAYTOPOINTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_arraytopointer bslmf_arraytopointer
15/// @brief Provide a meta-function to convert array types to pointer types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_arraytopointer
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_arraytopointer-purpose"> Purpose</a>
25/// * <a href="#bslmf_arraytopointer-classes"> Classes </a>
26/// * <a href="#bslmf_arraytopointer-description"> Description </a>
27/// * <a href="#bslmf_arraytopointer-usage"> Usage </a>
28///
29/// # Purpose {#bslmf_arraytopointer-purpose}
30/// Provide a meta-function to convert array types to pointer types.
31///
32/// # Classes {#bslmf_arraytopointer-classes}
33///
34/// - bslmf::ArrayToPointer: convert an array type to a pointer type
35/// - bslmf::ArrayToConstPointer: convert an array type to a `const` pointer type
36///
37/// @see bslmf_isarray, bslmf_forwardingtype
38///
39/// # Description {#bslmf_arraytopointer-description}
40/// This component provides a meta function for converting array
41/// types to pointer types. The utility is generally used for in templates that
42/// require forwarding or storage of arguments that are passed a arrays(e.g.,
43/// "string literals"). For non array types, the type is left unmodified. Note
44/// that `bslmf::ArrayToPointer` and `bslmf::ArrayToConstPointer` retain the CV
45/// qualifiers of the original type. In other words, if the original array type
46/// was `const` or `volatile`, or `const volatile`, the converted pointer type
47/// will also be `const`, `volatile`, or `const volatile` respectively.
48///
49/// When an explicit const pointer pointer type is needed(such as when accepting
50/// as argument, then `bslmf::ArrayToConstPointer` should be used.
51///
52/// ## Usage {#bslmf_arraytopointer-usage}
53///
54///
55/// For example:
56/// @code
57/// assert(1 == bsl::is_same<bslmf::ArrayToPointer<int[5]>::Type
58/// , int *>::value);
59/// assert(1 == bsl::is_same<bslmf::ArrayToPointer<int *>::Type
60/// , int *>::value);
61/// assert(0 == bsl::is_same<bslmf::ArrayToPointer<int (*)[5]>::Type]
62/// , int **>::value);
63/// @endcode
64/// @}
65/** @} */
66/** @} */
67
68/** @addtogroup bsl
69 * @{
70 */
71/** @addtogroup bslmf
72 * @{
73 */
74/** @addtogroup bslmf_arraytopointer
75 * @{
76 */
77
78#include <bslscm_version.h>
79
80#include <cstddef> // for 'std::size_t'
81
82
83
84namespace bslmf {
85
86 // =====================
87 // struct ArrayToPointer
88 // =====================
89
90template <class t_TYPE, class t_ORIGINAL_TYPE>
91struct ArrayToPointer_Imp;
92
93template <class t_TYPE>
97
98template <class t_TYPE>
99struct ArrayToPointer<t_TYPE&> {
101};
102
103 // ==========================
104 // struct ArrayToConstPointer
105 // ==========================
106
107template <class t_TYPE>
111
112template <class t_TYPE>
116
117 // =========================
118 // struct ArrayToPointer_Imp
119 // =========================
120
121template <class t_TYPE, class t_ORIGINAL_TYPE>
123 typedef t_ORIGINAL_TYPE Type;
124};
125
126template <class t_TYPE, std::size_t t_NUM_ELEMENTS, class t_UNUSED>
127struct ArrayToPointer_Imp<t_TYPE[t_NUM_ELEMENTS], t_UNUSED> {
128 typedef t_TYPE *Type;
129};
130
131template <class t_TYPE, class t_UNUSED>
132struct ArrayToPointer_Imp<t_TYPE[], t_UNUSED> {
133 typedef t_TYPE *Type;
134};
135
136} // close package namespace
137
138#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
139// ============================================================================
140// BACKWARD COMPATIBILITY
141// ============================================================================
142
143#ifdef bslmf_ArrayToConstPointer
144#undef bslmf_ArrayToConstPointer
145#endif
146/// This alias is defined for backward compatibility.
147#define bslmf_ArrayToConstPointer bslmf::ArrayToConstPointer
148
149#ifdef bslmf_ArrayToPointer
150#undef bslmf_ArrayToPointer
151#endif
152/// This alias is defined for backward compatibility.
153#define bslmf_ArrayToPointer bslmf::ArrayToPointer
154#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
155
156
157
158#endif
159
160// ----------------------------------------------------------------------------
161// Copyright 2013 Bloomberg Finance L.P.
162//
163// Licensed under the Apache License, Version 2.0 (the "License");
164// you may not use this file except in compliance with the License.
165// You may obtain a copy of the License at
166//
167// http://www.apache.org/licenses/LICENSE-2.0
168//
169// Unless required by applicable law or agreed to in writing, software
170// distributed under the License is distributed on an "AS IS" BASIS,
171// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
172// See the License for the specific language governing permissions and
173// limitations under the License.
174// ----------------------------- END-OF-FILE ----------------------------------
175
176/** @} */
177/** @} */
178/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576
ArrayToPointer_Imp< constt_TYPE, t_TYPE & >::Type Type
Definition bslmf_arraytopointer.h:114
Definition bslmf_arraytopointer.h:108
ArrayToPointer_Imp< constt_TYPE, t_TYPE >::Type Type
Definition bslmf_arraytopointer.h:109
ArrayToPointer_Imp< t_TYPE, t_TYPE & >::Type Type
Definition bslmf_arraytopointer.h:100
t_TYPE * Type
Definition bslmf_arraytopointer.h:133
t_TYPE * Type
Definition bslmf_arraytopointer.h:128
Definition bslmf_arraytopointer.h:122
t_ORIGINAL_TYPE Type
Definition bslmf_arraytopointer.h:123
Definition bslmf_arraytopointer.h:94
ArrayToPointer_Imp< t_TYPE, t_TYPE >::Type Type
Definition bslmf_arraytopointer.h:95