| Home | Libraries | People | FAQ | More

## Struct template constructible_with_allocator_prefix

boost::container::constructible_with_allocator_prefix

## Synopsis

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

    template<typename T>
    struct constructible_with_allocator_prefix {
    };

## Description

Remark: if a specialization is derived from true_type, indicates that T may be constructed with allocator_arg and T::allocator_type as its first two constructor arguments. Ideally, all constructors of T (including the copy and move constructors) should have a variant that accepts these two initial arguments.

Requires: if a specialization is derived from true_type, T must have a nested type, allocator_type and at least one constructor for which allocator_arg_t is the first parameter and allocator_type is the second parameter. If not all constructors of T can be called with these initial arguments, and if T is used in a context where a container must call such a constructor, then the program is ill-formed.

[Example: template <class T, class Allocator = allocator<T> > class Y { public: typedef Allocator allocator_type;

Default constructor with and allocator-extended default constructor Y(); Y(allocator_arg_t, const allocator_type& a);

Copy constructor and allocator-extended copy constructor Y(const Y& yy); Y(allocator_arg_t, const allocator_type& a, const Y& yy);

Variadic constructor and allocator-extended variadic constructor template<class ...Args> Y(Args&& args...); template<class ...Args> Y(allocator_arg_t, const allocator_type& a, Args&&... args); };

Specialize trait for class template Y template <class T, class Allocator = allocator<T> > struct constructible_with_allocator_prefix<Y<T,Allocator> > : ::boost::true_type { };

-- end example]

Note: This trait is a workaround inspired by "N2554: The Scoped Allocator 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.