
On 13 February 2013 07:20, Krzysztof Czainski <1czajnik@gmail.com> wrote:
Thank you, Nevin, for the above example. I think I see your point now. Furthermore, it gives me an idea: template < class T > struct MyAllocator : std::allocator<T> { using std::allocator<T>::construct;
// for v.emplace_back(noinit); void construct( T* c, noinit_t/*, typename boost::enable_if< boost::is_pod<T> >::type* = 0*/ ) {}
};
I wouldn't even bother with the enable_if; just use the default initialization placement new syntax when no arguments are passed, as in: // direct initialization template<typename... Args> void construct(T* c, Args&&... args) { ::new (static_cast<void*>(c)) T(std::forward<Args>(args)... ); } // default initialization for zero arguments void construct(T* c) { ::new (static_cast<void*>(c)) T; } Note: there is a bit more work that has to be done for allocators than just deriving from std::allocator<A>; for instance, rebind won't do the right thing. I don't think this can be done for resize(), can it?
Works for resize too under C++11. -- Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404