BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_usesallocator

Detailed Description

Outline

Purpose

Provide a meta-function to determine if a type uses an allocator.

Classes

See also
bslmf_isconvertible

Description

This component defines a meta-function, bsl::uses_allocator, that may be used to query whether a given type uses a given allocator type.

bsl::uses_allocator meets the requirements of the uses_allocator template defined in the C++11 standard [allocator.uses.trait], in addition to providing a welcome availability in both C++03 and C++11 compilation environments.

A type T uses an allocator type A if A has a nested alias named allocator_type and A is convertible to allocator_type (as defined in the bslmf_isconvertible component). If a type T uses an allocator type A, then T has a constructor that takes either 1) allocator_arg_t as a first argument and A as a second argument, or 2) A as the last argument. Alternatively, the uses_allocator template may be specialized for a type T that does not have a nested alias named allocator_type, where T can be constructed with A as detailed above.

Note that the template variable uses_allocator_v is defined in the C++17 standard as an inline variable. If the current compiler supports the inline variable C++17 compiler feature, bsl::uses_allocator_v is defined as an inline constexpr bool variable. Otherwise, if the compiler supports the variable templates C++14 compiler feature, bsl::uses_allocator_v is defined as a non-inline constexpr bool variable. See BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES and BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES macros in bsls_compilerfeatures component for details.

Usage

In this section we show intended use of this component.

TBD: finish up usage example, add to test driver.

Example 1: Determine If a Type Uses an Allocator

template <class CONTAINER>
class ContainerAdaptor {
// ...
public:
ContainerAdaptor();
// Create an empty container adaptor. No allocator will be provided
// to the underlying container, and the container's memory
// allocation will be provided by whatever is the default for the
// container type.
template <class t_ALLOC>
explicit
ContainerAdaptor(const t_ALLOC& basicAllocator,
typename bsl::enable_if<
t_ALLOC>::type * = 0);
// Create an empty container adaptor, and use the specified
// 'basicAllocator' to supply memory. Note that this constructor is
// available only when the type of the argument is compatible with
// the allocator type associated with the container.
// ...
};
Definition bslmf_enableif.h:525
Definition bslmf_usesallocator.h:165