BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_usesallocatorargt.h
Go to the documentation of this file.
1/// @file bslmf_usesallocatorargt.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_usesallocatorargt.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_USESALLOCATORARGT
9#define INCLUDED_BSLMF_USESALLOCATORARGT
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_usesallocatorargt bslmf_usesallocatorargt
15/// @brief Provide a metafunction for `allocator_arg_t` construction
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_usesallocatorargt
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_usesallocatorargt-purpose"> Purpose</a>
25/// * <a href="#bslmf_usesallocatorargt-classes"> Classes </a>
26/// * <a href="#bslmf_usesallocatorargt-description"> Description </a>
27/// * <a href="#bslmf_usesallocatorargt-usage"> Usage </a>
28///
29/// # Purpose {#bslmf_usesallocatorargt-purpose}
30/// Provide a metafunction for `allocator_arg_t` construction
31///
32/// # Classes {#bslmf_usesallocatorargt-classes}
33///
34/// - bslmf::UsesAllocatorArgT: metafunction for `allocator_arg_t` checking
35///
36/// @see bslmf_allocatorargt
37///
38/// # Description {#bslmf_usesallocatorargt-description}
39/// C++11 introduced an idiom for passing allocators to the
40/// constructors of classes in situations where putting the allocator as the
41/// last argument would have been ambiguous. For example, in cases where the
42/// type and number of arguments is unknown at specification time, it can be
43/// difficult or impossible to determine if the last argument should be used as
44/// the allocator for the constructed object.
45///
46/// The idiom adopted is to pass an object of the empty tag class
47/// `std::allocator_arg_t` (or `bsl::allocator_arg_t`, within the BSL library)
48/// as the first argument in the constructor, followed immediately by the
49/// allocator argument.
50///
51/// The `UsesAllocatorArgT<T>` metafunction inherits from `true_type` of `T` is
52/// one of the classes that uses this idiom; otherwise `false_type`. It is used
53/// when constructing elements of a container or members of a class template, to
54/// determine whether and how to pass an allocator to that element or member.
55/// By default, any `T` is assumed NOT to use the `allocator_arg_t` idiom.
56/// Specialization of this trait is required for classes that do use this idiom.
57/// Although a C++11 trait could be designed to automatically determine whether
58/// class `T` uses the idiom for a specific set of constructor arguments, such
59/// code would not be portable to C++03 compilers, a requirement for BSL
60/// classes.
61///
62/// Given a type `T" where `bslmf::UsesAllocatorArgT<T>::value' is true, if
63/// `bslma::UsesBslmaAllocator<T>::value` is also true, then the argument after
64/// `allocator_arg` can be of type `bslma::Allocator*`; otherwise, it must be of
65/// a type that meets the STL allocator requirements.
66///
67/// ## Usage {#bslmf_usesallocatorargt-usage}
68///
69///
70/// @}
71/** @} */
72/** @} */
73
74/** @addtogroup bsl
75 * @{
76 */
77/** @addtogroup bslmf
78 * @{
79 */
80/** @addtogroup bslmf_usesallocatorargt
81 * @{
82 */
83
84#include <bslscm_version.h>
85
87
88
89
90namespace bslmf {
91
92 // ================================
93 // class template UsesAllocatorArgT
94 // ================================
95
96/// User-specialized trait type indicating that the constructor of `t_TYPE`
97/// can be invoked using `bsl::allocator_arg` as its first argument and an
98/// allocator object as its second argument.
99template <class t_TYPE>
100struct UsesAllocatorArgT : DetectNestedTrait<t_TYPE, UsesAllocatorArgT>::type {
101};
102
103/// Trait metafunction that determines whether the constructor of `t_TYPE`
104/// can be invoked using `bsl::allocator_arg` as its first argument and an
105/// allocator object as its second argument. The value is computed by
106/// stripping off the cv-qualifier and forwading to
107/// `UsesAllocatorArgT<t_TYPE>`, which is user-specialized for the
108/// appropriate types.
109template <class t_TYPE>
110struct UsesAllocatorArgT<const t_TYPE> : UsesAllocatorArgT<t_TYPE>::type {
111};
112
113/// Trait metafunction that determines whether the constructor of `t_TYPE`
114/// can be invoked using `bsl::allocator_arg` as its first argument and an
115/// allocator object as its second argument. The value is computed by
116/// stripping off the cv-qualifier and forwading to
117/// `UsesAllocatorArgT<t_TYPE>`, which is user-specialized for the
118/// appropriate types.
119template <class t_TYPE>
120struct UsesAllocatorArgT<volatile t_TYPE> : UsesAllocatorArgT<t_TYPE>::type {
121};
122
123/// Trait metafunction that determines whether the constructor of `t_TYPE`
124/// can be invoked using `bsl::allocator_arg` as its first argument and an
125/// allocator object as its second argument. The value is computed by
126/// stripping off the cv-qualifier and forwading to
127/// `UsesAllocatorArgT<t_TYPE>`, which is user-specialized for the
128/// appropriate types.
129template <class t_TYPE>
130struct UsesAllocatorArgT<const volatile t_TYPE>
131: UsesAllocatorArgT<t_TYPE>::type {
132};
133
134} // close package namespace
135
136
137
138#endif // ! defined(INCLUDED_BSLMF_USESALLOCATORARGT)
139
140// ----------------------------------------------------------------------------
141// Copyright 2016 Bloomberg Finance L.P.
142//
143// Licensed under the Apache License, Version 2.0 (the "License");
144// you may not use this file except in compliance with the License.
145// You may obtain a copy of the License at
146//
147// http://www.apache.org/licenses/LICENSE-2.0
148//
149// Unless required by applicable law or agreed to in writing, software
150// distributed under the License is distributed on an "AS IS" BASIS,
151// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
152// See the License for the specific language governing permissions and
153// limitations under the License.
154// ----------------------------- END-OF-FILE ----------------------------------
155
156/** @} */
157/** @} */
158/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576
Definition bslmf_detectnestedtrait.h:464
Definition bslmf_usesallocatorargt.h:100