BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_inplace.h
Go to the documentation of this file.
1/// @file bslstl_inplace.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_inplace.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_INPLACE
9#define INCLUDED_BSLSTL_INPLACE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_inplace bslstl_inplace
15/// @brief Provide a standard-compliant in place construction tag types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_inplace
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_inplace-purpose"> Purpose</a>
25/// * <a href="#bslstl_inplace-classes"> Classes </a>
26/// * <a href="#bslstl_inplace-canonical-header"> Canonical Header </a>
27/// * <a href="#bslstl_inplace-description"> Description </a>
28///
29/// # Purpose {#bslstl_inplace-purpose}
30/// Provide a standard-compliant in place construction tag types.
31///
32/// # Classes {#bslstl_inplace-classes}
33///
34/// - bsl::in_place_t: tag type for in-place construction
35/// - bsl::in_place_type_t: tag type for in-place construction of a given type
36/// - bsl::in_place_index_t: tag type for in-place construction at a given index
37///
38/// # Canonical Header {#bslstl_inplace-canonical-header}
39/// bsl_utility.h
40///
41/// # Description {#bslstl_inplace-description}
42/// This component provides an implementation of standard
43/// compliant tag types for in-place construction: `bsl::in_place_t`,
44/// `bsl::in_place_type_t`, and `bsl::in_place_index_t`. Tag type
45/// `bsl::in_place_t` is used in constructors of `bsl::optional` to indicate
46/// that the contained object should be constructed in-place. Tag type
47/// `bsl::in_place_type_t<TYPE>` is used in constructors of `bsl::variant` to
48/// indicate that the object of type `TYPE` should be constructed in-place. Tag
49/// type `bsl::in_place_index_t<INDEX>` is used in constructors of
50/// `bsl::variant` to indicate that the alternative with index `INDEX` should
51/// be constructed in-place.
52///
53/// @see bslstl_optional, bslstl_variant
54/// @}
55/** @} */
56/** @} */
57
58/** @addtogroup bsl
59 * @{
60 */
61/** @addtogroup bslstl
62 * @{
63 */
64/** @addtogroup bslstl_inplace
65 * @{
66 */
67
68#include <bslscm_version.h>
69
71#include <bsls_keyword.h>
73
74#include <stddef.h>
75
76#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
77#include <utility> // for std::in_place_t
78#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
79
80namespace bsl {
81
82#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
83
84using std::in_place_t;
85using std::in_place;
86
87using std::in_place_type_t;
88using std::in_place_type;
89
90using std::in_place_index_t;
91using std::in_place_index;
92#else
93
94 // ================
95 // class in_place_t
96 // ================
97
98/// This trivial tag type is passed to the constructors of types that
99/// contain a single object to indicate that the contained object should be
100/// constructed in-place.
101///
102/// See @ref bslstl_inplace
104
105 // CREATORS
106
107 /// Create an `in_place_t` value.
108#if defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
109 explicit BSLS_KEYWORD_CONSTEXPR in_place_t() = default;
110#else
112#endif
113};
114
115// CREATORS
116#if !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
117inline
119{
120 // This `constexpr` function has to be defined before initializing the
121 // `constexpr` value, `in_place`, below.
122}
123#endif // !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
124
125/// Value of type `in_place_t` used as an argument to functions that take an
126/// `in_place_t` argument.
127#if defined(BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES)
128inline constexpr in_place_t in_place = in_place_t();
129#else
130extern const in_place_t in_place;
131#endif
132
133 // =====================
134 // class in_place_type_t
135 // =====================
136
137/// This trivial tag type is passed to the constructors of types that can
138/// contain objects of multiple types to indicate the type of contained
139/// object to create.
140///
141/// See @ref bslstl_inplace
142template <class TYPE>
144
145 // CREATORS
146
147 /// Create an `in_place_type_t` value. On platforms that allow for
148 /// defaulted special member functions, we opt for the compiler provided
149 /// one too keep the type trivial.
150#if defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
151 explicit BSLS_KEYWORD_CONSTEXPR in_place_type_t() = default;
152#else
154#endif
155};
156
157// CREATORS
158#if !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
159template <class TYPE>
160inline
165#endif // !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
166
167#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
168/// Value of type `in_place_type_t<TYPE>` used as an argument to functions
169/// that take an `in_place_type_t` argument.
170template <class TYPE>
172#endif
173
174 // ======================
175 // class in_place_index_t
176 // ======================
177
178/// This trivial tag type is passed to the constructors of `bsl::variant` to
179/// indicate the index of the alternative to create.
180///
181/// See @ref bslstl_inplace
182template <size_t INDEX>
184
185 // CREATORS
186
187 /// Create an `in_place_index_t` object. This constructor is trivial if
188 /// the platform supports defaulted special member functions.
189#if defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
190 explicit BSLS_KEYWORD_CONSTEXPR in_place_index_t() = default;
191#else
193#endif
194};
195
196// CREATORS
197#if !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
198template <size_t INDEX>
199inline
204#endif //!defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
205
206#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
207/// Value of type `in_place_index_t<INDEX>` used as an argument to functions
208/// that take an `in_place_index_t` argument.
209template <size_t INDEX>
211#endif
212
213#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
214
215} // close namespace bsl
216
217#endif // INCLUDED_BSLSTL_INPLACE
218
219// ----------------------------------------------------------------------------
220// Copyright 2020 Bloomberg Finance L.P.
221//
222// Licensed under the Apache License, Version 2.0 (the "License");
223// you may not use this file except in compliance with the License.
224// You may obtain a copy of the License at
225//
226// http://www.apache.org/licenses/LICENSE-2.0
227//
228// Unless required by applicable law or agreed to in writing, software
229// distributed under the License is distributed on an "AS IS" BASIS,
230// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
231// See the License for the specific language governing permissions and
232// limitations under the License.
233// ----------------------------- END-OF-FILE ----------------------------------
234
235/** @} */
236/** @} */
237/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:665
Definition bdlat_valuetypefunctions.h:939
const in_place_t in_place
Definition bslstl_inplace.h:183
BSLS_KEYWORD_CONSTEXPR in_place_index_t() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_inplace.h:201
Definition bslstl_inplace.h:103
BSLS_KEYWORD_CONSTEXPR in_place_t() BSLS_KEYWORD_NOEXCEPT
Create an in_place_t value.
Definition bslstl_inplace.h:118
Definition bslstl_inplace.h:143
BSLS_KEYWORD_CONSTEXPR in_place_type_t() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_inplace.h:162