Why is allocator::construct() called with one argument for '--std=c++0x'?

Jonathan Wakely jwakely.gcc@gmail.com
Fri Nov 11 00:54:00 GMT 2011


On 10 November 2011 23:49, Syncopated wrote:
>
> I'm using gcc 4.6.2. I tried to compile a program involving TBB 3.0 with the
> following line and got a compilation error.
>
> vector<int, tbb::cache_aligned_allocator<int> > values(0);
>
> It turns out that  bits/stl_uninitialized.h is calling
> allocator::construct() with only one argument, and
> tbb::cache_aligned_allocator doesn't define it. AFAIK, construct() takes two
> arguments. Is this something new in C++11, that construct() can take one
> argument?

Yes, the signature is now:

template<class U, class... Args>
  void construct(U* p, Args&&... args);

So can take any number of arguments, which are passed on to the constructor.

However in C++11 calls to allocators should be done through
allcoator_traits, which abstracts the differences between C++03
allocators and C++11 allocators, so it will work with allocators that
only support the old 2-argument construct() signature.  Unfortunately
we have only implemented allocator_traits in the unreleased GCC 4.7,
i.e. the subversion trunk.

In that code the code looks like this:
  __traits::construct(__alloc, std::__addressof(*__cur));
instead of
  __alloc.construct(std::__addressof(*__cur));



More information about the Libstdc++ mailing list