> is this a common thing, that non-standard pointer types are used for allocators?
Most of the time, the allocator would be
std::allocator<> and its 'pointer' would be a raw pointer.
When user-defined allocators are used, it is not unusual for the allocator's pointer to be a smart pointer.
If we are writing a generic component which is allocator aware, we need to also cater to the possibility that the allocator's 'pointer' may not be a raw pointer.
> construction of those objects can take place without generating temporary copies,
> if we're using .construct and pre-C++11 semantics? This is merely a performance concern.
C++, from its inception has always had the as-if rule
http://en.cppreference.com/w/cpp/language/as_if . If the implementation of the allocator's allocate function is visible to the compiler (the usual case) and copy construction of the object has no observable side effect, most implementations would optimise away the creation and then copying of the temporary object.
For instance, look at the code generated for 'foo' by clang++ and g++ in C++98 mode:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <new>
struct A { A( int a, int b ) : aval(a), bval(b) {} int aval ; int bval ; };
A* construct( void* here, const A& v ) { return new(here) A(v) ; }
A* foo( char* buffer, int a, int b )
{
A temp( a, b ) ;
A* p = buffer ? construct( buffer, temp ) : 0 ;
return p ;
}
|
http://coliru.stacked-crooked.com/a/2507eff0a909ed14