| Home | Libraries | People | FAQ | More

## Struct template constructible_with_allocator_suffix

boost::container::constructible_with_allocator_suffix

## Synopsis

    // In header: <boost/container/uses_allocator.hpp>

    template<typename T>
    struct constructible_with_allocator_suffix {

      // public data members
      static const bool value;
    };

## Description

Remark: if a specialization constructible_with_allocator_suffix<X>::value is true, indicates that T may be constructed with an allocator as its last constructor argument. Ideally, all constructors of T (including the copy and move constructors) should have a variant that accepts a final argument of allocator_type.

Requires: if a specialization constructible_with_allocator_suffix<X>::value is true, T must have a nested type, allocator_type and at least one constructor for which allocator_type is the last parameter. If not all constructors of T can be called with a final allocator_type argument, and if T is used in a context where a container must call such a constructor, then the program is ill-formed.

`template <class T, class Allocator = allocator<T> > class Z { public: typedef Allocator allocator_type;`

`Default constructor with optional allocator suffix Z(const allocator_type& a = allocator_type());`

`Copy constructor and allocator-extended copy constructor Z(const Z& zz); Z(const Z& zz, const allocator_type& a); };`

`Specialize trait for class template Z template <class T, class Allocator = allocator<T> > struct constructible_with_allocator_suffix<Z<T,Allocator> > { static const bool value = true; };`

Note: This trait is a workaround inspired by "N2554: The Scoped A Model (Rev 2)" (Pablo Halpern, 2008-02-29) to backport the scoped allocator model to C++03, as in C++03 there is no mechanism to detect if a type can be constructed from arbitrary arguments. Applications aiming portability with several compilers should always define this trait.

In conforming C++11 compilers or compilers supporting SFINAE expressions (when BOOST_NO_SFINAE_EXPR is NOT defined), this trait is ignored and C++11 rules will be used to detect if a type should be constructed with suffix or prefix allocator arguments.