BDE 4.14.0 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-description"> Description </a>
27///
28/// # Purpose {#bslstl_inplace-purpose}
29/// Provide a standard-compliant in place construction tag types.
30///
31/// # Classes {#bslstl_inplace-classes}
32///
33/// - bsl::in_place_t: tag type for in-place construction
34/// - bsl::in_place_type_t: tag type for in-place construction of a given type
35/// - bsl::in_place_index_t: tag type for in-place construction at a given index
36///
37/// **Canonical header:** bsl_utility.h
38///
39/// # Description {#bslstl_inplace-description}
40/// This component provides an implementation of standard
41/// compliant tag types for in-place construction: `bsl::in_place_t`,
42/// `bsl::in_place_type_t`, and `bsl::in_place_index_t`. Tag type
43/// `bsl::in_place_t` is used in constructors of `bsl::optional` to indicate
44/// that the contained object should be constructed in-place. Tag type
45/// `bsl::in_place_type_t<TYPE>` is used in constructors of `bsl::variant` to
46/// indicate that the object of type `TYPE` should be constructed in-place. Tag
47/// type `bsl::in_place_index_t<INDEX>` is used in constructors of
48/// `bsl::variant` to indicate that the alternative with index `INDEX` should
49/// be constructed in-place.
50///
51/// @see bslstl_optional, bslstl_variant
52/// @}
53/** @} */
54/** @} */
55
56/** @addtogroup bsl
57 * @{
58 */
59/** @addtogroup bslstl
60 * @{
61 */
62/** @addtogroup bslstl_inplace
63 * @{
64 */
65
66#include <bslscm_version.h>
67
69#include <bsls_keyword.h>
71
72#include <stddef.h>
73
74#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
75#include <utility> // for std::in_place_t
76#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
77
78namespace bsl {
79
80#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
81
82using std::in_place_t;
83using std::in_place;
84
85using std::in_place_type_t;
86using std::in_place_type;
87
88using std::in_place_index_t;
89using std::in_place_index;
90#else
91
92 // ================
93 // class in_place_t
94 // ================
95
96/// This trivial tag type is passed to the constructors of types that
97/// contain a single object to indicate that the contained object should be
98/// constructed in-place.
99struct in_place_t {
100
101 // CREATORS
102
103 /// Create an `in_place_t` value.
104#if defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
105 explicit BSLS_KEYWORD_CONSTEXPR in_place_t() = default;
106#else
108#endif
109};
110
111// CREATORS
112#if !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
113inline
115{
116 // This `constexpr` function has to be defined before initializing the
117 // `constexpr` value, `in_place`, below.
118}
119#endif // !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
120
121/// Value of type `in_place_t` used as an argument to functions that take an
122/// `in_place_t` argument.
123#if defined(BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES)
124inline constexpr in_place_t in_place = in_place_t();
125#else
126extern const in_place_t in_place;
127#endif
128
129 // =====================
130 // class in_place_type_t
131 // =====================
132
133/// This trivial tag type is passed to the constructors of types that can
134/// contain objects of multiple types to indicate the type of contained
135/// object to create.
136template <class TYPE>
138
139 // CREATORS
140
141 /// Create an `in_place_type_t` value. On platforms that allow for
142 /// defaulted special member functions, we opt for the compiler provided
143 /// one too keep the type trivial.
144#if defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
145 explicit BSLS_KEYWORD_CONSTEXPR in_place_type_t() = default;
146#else
148#endif
149};
150
151// CREATORS
152#if !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
153template <class TYPE>
154inline
159#endif // !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
160
161#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
162/// Value of type `in_place_type_t<TYPE>` used as an argument to functions
163/// that take an `in_place_type_t` argument.
164template <class TYPE>
166#endif
167
168 // ======================
169 // class in_place_index_t
170 // ======================
171
172/// This trivial tag type is passed to the constructors of `bsl::variant` to
173/// indicate the index of the alternative to create.
174template <size_t INDEX>
176
177 // CREATORS
178
179 /// Create an `in_place_index_t` object. This constructor is trivial if
180 /// the platform supports defaulted special member functions.
181#if defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
182 explicit BSLS_KEYWORD_CONSTEXPR in_place_index_t() = default;
183#else
185#endif
186};
187
188// CREATORS
189#if !defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
190template <size_t INDEX>
191inline
196#endif //!defined(BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS)
197
198#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
199/// Value of type `in_place_index_t<INDEX>` used as an argument to functions
200/// that take an `in_place_index_t` argument.
201template <size_t INDEX>
203#endif
204
205#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
206
207} // close namespace bsl
208
209#endif // INCLUDED_BSLSTL_INPLACE
210
211// ----------------------------------------------------------------------------
212// Copyright 2020 Bloomberg Finance L.P.
213//
214// Licensed under the Apache License, Version 2.0 (the "License");
215// you may not use this file except in compliance with the License.
216// You may obtain a copy of the License at
217//
218// http://www.apache.org/licenses/LICENSE-2.0
219//
220// Unless required by applicable law or agreed to in writing, software
221// distributed under the License is distributed on an "AS IS" BASIS,
222// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
223// See the License for the specific language governing permissions and
224// limitations under the License.
225// ----------------------------- END-OF-FILE ----------------------------------
226
227/** @} */
228/** @} */
229/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:623
Definition bdlb_printmethods.h:283
const in_place_t in_place
Definition bslstl_inplace.h:175
BSLS_KEYWORD_CONSTEXPR in_place_index_t() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_inplace.h:193
Definition bslstl_inplace.h:99
BSLS_KEYWORD_CONSTEXPR in_place_t() BSLS_KEYWORD_NOEXCEPT
Create an in_place_t value.
Definition bslstl_inplace.h:114
Definition bslstl_inplace.h:137
BSLS_KEYWORD_CONSTEXPR in_place_type_t() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_inplace.h:156