/* Copyright 2019 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_CORE_NOINIT_ADAPTOR_HPP #define BOOST_CORE_NOINIT_ADAPTOR_HPP #include #if !defined(BOOST_NO_CXX11_ALLOCATOR) #include #endif #include #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #include #endif namespace boost { template struct noinit_adaptor : A { template struct rebind { #if !defined(BOOST_NO_CXX11_ALLOCATOR) typedef noinit_adaptor::template rebind_alloc > other; #else typedef noinit_adaptor::other> other; #endif }; noinit_adaptor() : A() { } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template noinit_adaptor(U&& u) BOOST_NOEXCEPT : A(std::forward(u)) { } #else template noinit_adaptor(const U& u) BOOST_NOEXCEPT : A(u) { } #endif template noinit_adaptor(const noinit_adaptor& u) BOOST_NOEXCEPT : A(static_cast(u)) { } template void construct(U* p) { ::new((void*)p) U; } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template void construct(U* p, V&& v, Args&&... args) { ::new((void*)p) U(std::forward(v), std::forward(args)...); } #else template void construct(U* p, V&& v) { ::new((void*)p) U(std::forward(v)); } #endif #else template void construct(U* p, const V& v) { ::new((void*)p) U(v); } template void construct(U* p, V& v) { ::new((void*)p) U(v); } #endif template void destroy(U* p) { p->~U(); } }; template inline bool operator==(const noinit_adaptor& lhs, const noinit_adaptor& rhs) BOOST_NOEXCEPT { return static_cast(lhs) == static_cast(rhs); } template inline bool operator!=(const noinit_adaptor& lhs, const noinit_adaptor& rhs) BOOST_NOEXCEPT { return !(lhs == rhs); } template inline noinit_adaptor noinit_adapt(const A& a) BOOST_NOEXCEPT { return noinit_adaptor(a); } } /* boost */ #endif