18 Nov
2003
18 Nov
'03
1:54 p.m.
Mark A. Gibbs wrote:
Peter Dimov wrote:
foo* bar = static_cast
(get_allocator().allocate(1)); new(bar) foo(args);
or
get_allocator().construct(bar, foo(args));
are these two expressions identical? I mean for any allocator (not just std::allocator<T>). The former looks more efficient but less general than the latter.
The short answer is that nobody knows, as allocators are underspecified (standardese for "a mess"). The standard says, in Table 32 - Allocator requirements, that a.construct(p, t) must have the effect new((void*)p) T(t). In addition, there is no guarantee that the standard library containers will bother to call construct() and not use placement new directly. So the choice which form to use is up to you. ;-)