Peter Dimov wrote:
copy of the standard). For instance, I'm not 100% sure whether or not I have to call construct() after allocate() and destroy() before deallocate().
Yes, you have to. allocate() gives you raw memory with the correct size and alignment, but there is no object in it. To create the object in that memory, you need to construct() it. Similarly, destroy() invokes the destructor and deallocate() only, well, deallocates.
Excellent. That's one big headache I avoid. but:
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.
No, scoped_* do not support allocators. Since they match raw pointers in size, they can keep no additional state such as an instance of, or a reference to, an allocator.
Ok, so that means i have to write my own scoped_allocator_ptr