23 General utilities library [utilities]

23.10 Memory [memory]

23.10.7 uses_­allocator [allocator.uses]

23.10.7.1 uses_­allocator trait [allocator.uses.trait]

template <class T, class Alloc> struct uses_allocator;

Remarks: Automatically detects whether T has a nested allocator_­type that is convertible from Alloc. Meets the BinaryTypeTrait requirements. The implementation shall provide a definition that is derived from true_­type if the qualified-id T​::​allocator_­type is valid and denotes a type ([temp.deduct]) and is_­convertible_­v<Alloc, T​::​allocator_­type> != false, otherwise it shall be derived from false_­type. A program may specialize this template to derive from true_­type for a user-defined type T that does not have a nested allocator_­type but nonetheless can be constructed with an allocator where either:

  • the first argument of a constructor has type allocator_­arg_­t and the second argument has type Alloc or

  • the last argument of a constructor has type Alloc.

23.10.7.2 Uses-allocator construction [allocator.uses.construction]

Uses-allocator construction with allocator Alloc refers to the construction of an object obj of type T, using constructor arguments v1, v2, ..., vN of types V1, V2, ..., VN, respectively, and an allocator alloc of type Alloc, according to the following rules:

  • if uses_­allocator_­v<T, Alloc> is false and is_­constructible_­v<T, V1, V2, ..., VN> is true, then obj is initialized as obj(v1, v2, ..., vN);

  • otherwise, if uses_­allocator_­v<T, Alloc> is true and is_­constructible_­v<T, allocator_­arg_­t, Alloc, V1, V2, ..., VN> is true, then obj is initialized as obj(allocator_­arg, alloc, v1, v2, ..., vN);

  • otherwise, if uses_­allocator_­v<T, Alloc> is true and is_­constructible_­v<T, V1, V2, ..., VN, Alloc> is true, then obj is initialized as obj(v1, v2, ..., vN, alloc);

  • otherwise, the request for uses-allocator construction is ill-formed. [Note: An error will result if uses_­allocator_­v<T, Alloc> is true but the specific constructor does not take an allocator. This definition prevents a silent failure to pass the allocator to an element. end note]