BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmf_removeextent.h
Go to the documentation of this file.
1/// @file bslmf_removeextent.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_removeextent.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_REMOVEEXTENT
9#define INCLUDED_BSLMF_REMOVEEXTENT
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_removeextent bslmf_removeextent
15/// @brief Provide a metafunction to return an array type's element type.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_removeextent
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_removeextent-purpose"> Purpose</a>
25/// * <a href="#bslmf_removeextent-classes"> Classes </a>
26/// * <a href="#bslmf_removeextent-description"> Description </a>
27/// * <a href="#bslmf_removeextent-usage"> Usage </a>
28///
29/// # Purpose {#bslmf_removeextent-purpose}
30/// Provide a metafunction to return an array type's element type.
31///
32/// # Classes {#bslmf_removeextent-classes}
33///
34/// - bsl::remove_extent: type trait that returns the element type of an array
35/// - bsl::remove_extent_t: alias to the return type of the `bsl::remove_extent`
36///
37/// @see bslmf_decay
38///
39/// # Description {#bslmf_removeextent-description}
40/// This component provides a metafunction `bsl::remove_extent`
41/// that returns the element type of an array. The functionality is intended to
42/// be identical to the C++11 metafunction `std::remove_extent`. From the C++14
43/// standard:
44///
45/// If `T` names a type "array of `U`", the member typedef `type` shall be `U`,
46/// otherwise `T`. [ *Note:* For multidimensional arrays, only the first array
47/// dimension is removed. For a type "array of `const U`", the resulting type
48/// is `const U`. -- *end note* ]
49///
50/// ## Usage {#bslmf_removeextent-usage}
51///
52///
53/// The class template `Traverser` is used to traverse an array and perform some
54/// operation. In order to do its job in the case of two-dimensional arrays,
55/// `Traverser` must hold on to an entire row of the array at a time in order to
56/// process it correctly. The row type is determined from the array type using
57/// @ref remove_extent :
58/// @code
59/// template <class ARRAY_TYPE>
60/// class Traverser {
61/// public:
62///
63/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
64/// @endcode
65/// Note that if the current compiler supports alias templates C++11 feature, we
66/// can use `bsl::remove_extent_t` alias to the "result" type of the
67/// `bsl::remove_extent` meta-function, that avoids the `::type` suffix and
68/// `typename` prefix in the declaration of the function return type:
69/// @code
70/// using RowType = bsl::remove_extent_t<ARRAY_TYPE>;
71/// #else
72/// typedef typename bsl::remove_extent<ARRAY_TYPE>::type RowType;
73/// #endif
74///
75/// private:
76/// RowType d_row; // Might be scalar
77/// // ...
78///
79/// // CREATORS
80/// Traverser() : d_row() {}
81/// };
82/// @endcode
83/// Now we can see that the row type is the type of the array after having
84/// striped off the high-order dimension:
85/// @code
86/// int main()
87/// {
88/// assert((bsl::is_same<int, Traverser<int>::RowType>::value));
89/// assert((bsl::is_same<int, Traverser<int[]>::RowType>::value));
90/// assert((bsl::is_same<int, Traverser<int[5]>::RowType>::value));
91/// typedef const int MyRow[6];
92/// assert((bsl::is_same<MyRow, Traverser<MyRow[]>::RowType>::value));
93/// assert((bsl::is_same<int[6], Traverser<int[7][6]>::RowType>::value));
94///
95/// return 0;
96/// }
97/// @endcode
98/// @}
99/** @} */
100/** @} */
101
102/** @addtogroup bsl
103 * @{
104 */
105/** @addtogroup bslmf
106 * @{
107 */
108/** @addtogroup bslmf_removeextent
109 * @{
110 */
111
112#include <bslscm_version.h>
113
115
116#include <cstddef>
117
118namespace bsl {
119
120 // ============================
121 // class template remove_extent
122 // ============================
123
124/// From the C++14 standard: If `T` names a type "array of `U`", the member
125/// typedef `type` shall be `U`, otherwise `T`. [ *Note:* For
126/// multidimensional arrays, only the first array dimension is removed. For
127/// a type "array of `const U`", the resulting type is `const U`. -- *end
128/// note* ]
129///
130/// See @ref bslmf_removeextent
131template <class t_TYPE>
133
134 typedef t_TYPE type;
135};
136
137/// Specialization of @ref remove_extent for array of unknown bound
138template <class t_TYPE>
139struct remove_extent<t_TYPE[]> {
140
141 typedef t_TYPE type;
142};
143
144/// Specialization of @ref remove_extent for array of known bound
145template <class t_TYPE, std::size_t t_SZ>
146struct remove_extent<t_TYPE[t_SZ]> {
147
148 typedef t_TYPE type;
149};
150
151#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
152
153// ALIASES
154
155/// @ref remove_extent_t is an alias to the return type of the
156/// `bsl::remove_extent` meta-function. Note, that the @ref enable_if_t avoids
157/// the `::type` suffix and `typename` prefix when we want to use the result
158/// of the meta-function in templates.
159template <class t_TYPE>
160using remove_extent_t = typename remove_extent<t_TYPE>::type;
161
162#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
163
164} // close namespace bsl
165
166#endif // ! defined(INCLUDED_BSLMF_REMOVEEXTENT)
167
168// ----------------------------------------------------------------------------
169// Copyright 2019 Bloomberg Finance L.P.
170//
171// Licensed under the Apache License, Version 2.0 (the "License");
172// you may not use this file except in compliance with the License.
173// You may obtain a copy of the License at
174//
175// http://www.apache.org/licenses/LICENSE-2.0
176//
177// Unless required by applicable law or agreed to in writing, software
178// distributed under the License is distributed on an "AS IS" BASIS,
179// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180// See the License for the specific language governing permissions and
181// limitations under the License.
182// ----------------------------- END-OF-FILE ----------------------------------
183
184/** @} */
185/** @} */
186/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlat_valuetypefunctions.h:939
t_TYPE type
Definition bslmf_removeextent.h:141
t_TYPE type
Definition bslmf_removeextent.h:148
Definition bslmf_removeextent.h:132
t_TYPE type
Definition bslmf_removeextent.h:134