Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bslmf_usesallocatorargt
[Package bslmf]

Provide a metafunction for allocator_arg_t construction. More...

Namespaces

namespace  bslmf

Detailed Description

Outline
Purpose:
Provide a metafunction for allocator_arg_t construction
Classes:
bslmf::UsesAllocatorArgT metafunction for allocator_arg_t checking
See also:
Component bslmf_allocatorargt
Description:
C++11 introduced an idiom for passing allocators to the constructors of classes in situations where putting the allocator as the last argument would have been ambiguous. For example, in cases where the type and number of arguments is unknown at specification time, it can be difficult or impossible to determine if the last argument should be used as the allocator for the constructed object.
The idiom adopted is to pass an object of the empty tag class std::allocator_arg_t (or bsl::allocator_arg_t, within the BSL library) as the first argument in the constructor, followed immediately by the allocator argument.
The UsesAllocatorArgT<T> metafunction inherits from true_type of T is one of the classes that uses this idiom; otherwise false_type. It is used when constructing elements of a container or members of a class template, to determine whether and how to pass an allocator to that element or member. By default, any T is assumed NOT to use the allocator_arg_t idiom. Specialization of this trait is required for classes that do use this idiom. Although a C++11 trait could be designed to automatically determine whether class T uses the idiom for a specific set of constructor arguments, such code would not be portable to C++03 compilers, a requirement for BSL classes.
Given a type T" where 'bslmfUsesAllocatorArgT<T>::value is true, if bslma::UsesBslmaAllocator<T>value is also true, then the argument after allocator_arg can be of type bslma::Allocator*; otherwise, it must be of a type that meets the STL allocator requirements.
Usage: