/** * Allocator adaptor that interposes construct() calls to convert value-initialization * (which is what you get with e.g. `vector::resize`) into default-initialization (which does not * zero out non-class types). * From https://stackoverflow.com/questions/21028299/is-this-behavior-of-vectorresizesize-type-n-under-c11-and-boost-container/21028912#21028912 */ #ifndef DEFAULT_INIT_ALLOC_H #define DEFAULT_INIT_ALLOC_H #include #include template> class default_init_allocator : public A { using a_t = std::allocator_traits; public: template struct rebind { using other = default_init_allocator>; }; using A::A; // Inherit the allocator's constructors template void construct(U * ptr) noexcept(std::is_nothrow_default_constructible_v) { ::new(static_cast(ptr)) U; } template void construct(U * ptr, Args && ... args) { a_t::construct(static_cast(*this), ptr, std::forward(args)...); } }; template using DefaultInitVec = std::vector>; #endif