BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_usesallocator.h
Go to the documentation of this file.
1/// @file bslmf_usesallocator.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_usesallocator.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_USESALLOCATOR
9#define INCLUDED_BSLMF_USESALLOCATOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_usesallocator bslmf_usesallocator
15/// @brief Provide a meta-function to determine if a type uses an allocator.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_usesallocator
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_usesallocator-purpose"> Purpose</a>
25/// * <a href="#bslmf_usesallocator-classes"> Classes </a>
26/// * <a href="#bslmf_usesallocator-description"> Description </a>
27/// * <a href="#bslmf_usesallocator-usage"> Usage </a>
28/// * <a href="#bslmf_usesallocator-example-1-determine-if-a-type-uses-an-allocator"> Example 1: Determine If a Type Uses an Allocator </a>
29///
30/// # Purpose {#bslmf_usesallocator-purpose}
31/// Provide a meta-function to determine if a type uses an allocator.
32///
33/// # Classes {#bslmf_usesallocator-classes}
34///
35/// - bsl::uses_allocator: meta-fn to check if a type uses a certain allocator
36/// - bsl::uses_allocator_v: the result value of `bsl::uses_allocator`
37///
38/// @see bslmf_isconvertible
39///
40/// # Description {#bslmf_usesallocator-description}
41/// This component defines a meta-function, `bsl::uses_allocator`,
42/// that may be used to query whether a given type uses a given allocator type.
43///
44/// `bsl::uses_allocator` meets the requirements of the @ref uses_allocator
45/// template defined in the C++11 standard [allocator.uses.trait], in addition
46/// to providing a welcome availability in both C++03 and C++11 compilation
47/// environments.
48///
49/// A type `T` uses an allocator type `A` if `A` has a nested alias named
50/// `allocator_type` and `A` is convertible to `allocator_type` (as defined in
51/// the @ref bslmf_isconvertible component). If a type `T` uses an allocator type
52/// `A`, then `T` has a constructor that takes either 1) `allocator_arg_t` as a
53/// first argument and `A` as a second argument, or 2) `A` as the last argument.
54/// Alternatively, the @ref uses_allocator template may be specialized for a type
55/// `T` that does not have a nested alias named `allocator_type`, where `T` can
56/// be constructed with `A` as detailed above.
57///
58/// Note that the template variable `uses_allocator_v` is defined in the C++17
59/// standard as an inline variable. If the current compiler supports the inline
60/// variable C++17 compiler feature, `bsl::uses_allocator_v` is defined as an
61/// `inline constexpr bool` variable. Otherwise, if the compiler supports the
62/// variable templates C++14 compiler feature, `bsl::uses_allocator_v` is
63/// defined as a non-inline `constexpr bool` variable. See
64/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
65/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
66/// bsls_compilerfeatures component for details.
67///
68/// ## Usage {#bslmf_usesallocator-usage}
69///
70///
71/// In this section we show intended use of this component.
72///
73/// TBD: finish up usage example, add to test driver.
74///
75/// ### Example 1: Determine If a Type Uses an Allocator {#bslmf_usesallocator-example-1-determine-if-a-type-uses-an-allocator}
76///
77///
78///
79/// @code
80/// template <class CONTAINER>
81/// class ContainerAdaptor {
82/// // ...
83/// public:
84/// ContainerAdaptor();
85/// // Create an empty container adaptor. No allocator will be provided
86/// // to the underlying container, and the container's memory
87/// // allocation will be provided by whatever is the default for the
88/// // container type.
89///
90/// template <class t_ALLOC>
91/// explicit
92/// ContainerAdaptor(const t_ALLOC& basicAllocator,
93/// typename bsl::enable_if<
94/// bsl::uses_allocator<CONTAINER, t_ALLOC>::value,
95/// t_ALLOC>::type * = 0);
96/// // Create an empty container adaptor, and use the specified
97/// // 'basicAllocator' to supply memory. Note that this constructor is
98/// // available only when the type of the argument is compatible with
99/// // the allocator type associated with the container.
100///
101/// // ...
102/// };
103/// @endcode
104///
105/// @}
106/** @} */
107/** @} */
108
109/** @addtogroup bsl
110 * @{
111 */
112/** @addtogroup bslmf
113 * @{
114 */
115/** @addtogroup bslmf_usesallocator
116 * @{
117 */
118
119#include <bslscm_version.h>
120
122#include <bslmf_isconvertible.h>
123#include <bslmf_voidtype.h>
124
126#include <bsls_keyword.h>
127
128
129namespace bslmf {
130
131/// This `struct` template derives from `bsl::false_type` when the (template
132/// parameter) type `t_TYPE` does not have a nested alias `allocator_type`.
133template <class t_TYPE, class t_ALLOC, class = void>
136
137/// This `struct` template derives from `bsl::true_type` when the (template
138/// parameter) `t_TYPE` has a nested alias `allocator_type` and the
139/// (template parameter) type `t_ALLOC` is convertible to
140/// `t_TYPE::allocator_type`, and `bsl::false_type` otherwise.
141template <class t_TYPE, class t_ALLOC>
142struct UsesAllocator_Imp<t_TYPE,
143 t_ALLOC,
144 BSLMF_VOIDTYPE(typename t_TYPE::allocator_type)>
145: bsl::is_convertible<t_ALLOC, typename t_TYPE::allocator_type>::type {
146};
147
148} // close package namespace
149
150
151namespace bsl {
152
153 // =====================
154 // struct uses_allocator
155 // =====================
156
157/// This `struct` template implements a meta-function to determine whether a
158/// (template parameter) `t_TYPE` uses a given (template parameter)
159/// `t_ALLOCATOR_TYPE`. This `struct` derives from `bsl::true_type` if
160/// `t_TYPE` uses `t_ALLOCATOR_TYPE` and from `bsl::false_type` otherwise.
161/// This meta-function has the same syntax as the @ref uses_allocator
162/// meta-function defined in the C++11 standard [allocator.uses.trait].
163template <class t_TYPE, class t_ALLOCATOR_TYPE>
165: BloombergLP::bslmf::UsesAllocator_Imp<t_TYPE, t_ALLOCATOR_TYPE>::type {
166};
167
168#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
169/// This template variable represents the result value of the
170/// `bsl::uses_allocator` meta-function.
171template <class t_TYPE, class t_ALLOCATOR_TYPE>
172BSLS_KEYWORD_INLINE_VARIABLE constexpr bool uses_allocator_v =
174#endif
175
176
177} // close namespace bsl
178
179#endif
180
181// ----------------------------------------------------------------------------
182// Copyright 2019 Bloomberg Finance L.P.
183//
184// Licensed under the Apache License, Version 2.0 (the "License");
185// you may not use this file except in compliance with the License.
186// You may obtain a copy of the License at
187//
188// http://www.apache.org/licenses/LICENSE-2.0
189//
190// Unless required by applicable law or agreed to in writing, software
191// distributed under the License is distributed on an "AS IS" BASIS,
192// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
193// See the License for the specific language governing permissions and
194// limitations under the License.
195// ----------------------------- END-OF-FILE ----------------------------------
196
197/** @} */
198/** @} */
199/** @} */
#define BSLMF_VOIDTYPE(ARG)
Definition bslmf_voidtype.h:335
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:623
Definition bdlb_printmethods.h:283
Definition bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244
Definition bslmf_isconvertible.h:867
Definition bslmf_usesallocator.h:165
Definition bslmf_usesallocator.h:134