#include #include #include #include using namespace std; struct noinit_t {}; noinit_t const noinit = {}; #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) struct listinit_t {}; listinit_t const listinit {}; #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template < class T > struct MyAllocator : std::allocator { using std::allocator::construct; // for v.emplace_back(noinit); void construct( T* c, noinit_t/*, typename boost::enable_if< boost::is_pod >::type* = 0*/ ) {} #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) // for v.emplace_back( listinit, ... ); template void construct(T* c, listinit_t, Args&&... args) { ::new (static_cast(c)) T{ std::forward(args)... }; } #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) }; int main() { #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) namespace cont = std; #else namespace cont = boost::container; #endif cont::vector< cont::vector, MyAllocator< cont::vector > > vm; vm.emplace_back(2); assert( 2 == vm.back().size() ); #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) vm.emplace_back( listinit, 2, 2, 2 ); vm.emplace_back( listinit, 2 ); assert( 1 == vm.back().size() ); #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) cont::vector< int, MyAllocator > vi; vi.emplace_back(5); vi.pop_back(); vi.emplace_back(noinit); assert( 0 != vi.back() ); }