BDE 4.14.0 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* ]
129template <class t_TYPE>
131
132 typedef t_TYPE type;
133};
134
135/// Specialization of @ref remove_extent for array of unknown bound
136template <class t_TYPE>
137struct remove_extent<t_TYPE[]> {
138
139 typedef t_TYPE type;
140};
141
142/// Specialization of @ref remove_extent for array of known bound
143template <class t_TYPE, std::size_t t_SZ>
144struct remove_extent<t_TYPE[t_SZ]> {
145
146 typedef t_TYPE type;
147};
148
149#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
150
151// ALIASES
152
153/// `remove_extent_t` is an alias to the return type of the
154/// `bsl::remove_extent` meta-function. Note, that the `enable_if_t` avoids
155/// the `::type` suffix and `typename` prefix when we want to use the result
156/// of the meta-function in templates.
157template <class t_TYPE>
158using remove_extent_t = typename remove_extent<t_TYPE>::type;
159
160#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
161
162} // close namespace bsl
163
164#endif // ! defined(INCLUDED_BSLMF_REMOVEEXTENT)
165
166// ----------------------------------------------------------------------------
167// Copyright 2019 Bloomberg Finance L.P.
168//
169// Licensed under the Apache License, Version 2.0 (the "License");
170// you may not use this file except in compliance with the License.
171// You may obtain a copy of the License at
172//
173// http://www.apache.org/licenses/LICENSE-2.0
174//
175// Unless required by applicable law or agreed to in writing, software
176// distributed under the License is distributed on an "AS IS" BASIS,
177// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
178// See the License for the specific language governing permissions and
179// limitations under the License.
180// ----------------------------- END-OF-FILE ----------------------------------
181
182/** @} */
183/** @} */
184/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
t_TYPE type
Definition bslmf_removeextent.h:139
t_TYPE type
Definition bslmf_removeextent.h:146
Definition bslmf_removeextent.h:130
t_TYPE type
Definition bslmf_removeextent.h:132