From 16386f586ff891311e4fa33fdda68493d33d1ac9 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Tue, 29 Aug 2023 11:02:19 -0700 Subject: [PATCH] Remove usage of BOOST_UNORDERED_CXX11_CONSTRUCTION --- include/boost/unordered/detail/fwd.hpp | 24 -- .../boost/unordered/detail/implementation.hpp | 302 +----------------- test/helpers/test.hpp | 2 - test/objects/test.hpp | 17 - 4 files changed, 1 insertion(+), 344 deletions(-) diff --git a/include/boost/unordered/detail/fwd.hpp b/include/boost/unordered/detail/fwd.hpp index 7fcb770e..1f23c8d1 100644 --- a/include/boost/unordered/detail/fwd.hpp +++ b/include/boost/unordered/detail/fwd.hpp @@ -123,28 +123,4 @@ namespace boost { #include #endif -// BOOST_UNORDERED_CXX11_CONSTRUCTION -// -// Use C++11 construction, requires variadic arguments, good construct support -// in allocator_traits and piecewise construction of std::pair -// Otherwise allocators aren't used for construction/destruction - -#if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT && \ - !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && BOOST_UNORDERED_TUPLE_ARGS -#if BOOST_COMP_SUNPRO && BOOST_LIB_STD_GNU -// Sun C++ std::pair piecewise construction doesn't seem to be exception safe. -// (At least for Sun C++ 12.5 using libstdc++). -#define BOOST_UNORDERED_CXX11_CONSTRUCTION 0 -#elif BOOST_COMP_GNUC && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(4, 7, 0) -// Piecewise construction in GCC 4.6 doesn't work for uncopyable types. -#define BOOST_UNORDERED_CXX11_CONSTRUCTION 0 -#elif !defined(BOOST_NO_CXX11_ALLOCATOR) -#define BOOST_UNORDERED_CXX11_CONSTRUCTION 1 -#endif -#endif - -#if !defined(BOOST_UNORDERED_CXX11_CONSTRUCTION) -#define BOOST_UNORDERED_CXX11_CONSTRUCTION 0 -#endif - #endif diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index 6483ad74..c9033cd9 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -62,10 +62,8 @@ #include -#if BOOST_UNORDERED_CXX11_CONSTRUCTION #include #include -#endif // BOOST_UNORDERED_SUPPRESS_DEPRECATED // @@ -520,57 +518,6 @@ namespace boost { } // namespace unordered } // namespace boost -//////////////////////////////////////////////////////////////////////////// -// Functions used to construct nodes. Emulates variadic construction, -// piecewise construction etc. - -//////////////////////////////////////////////////////////////////////////// -// construct_value -// -// Only use allocator_traits::construct, allocator_traits::destroy when full -// C++11 support is available. - -#if BOOST_UNORDERED_CXX11_CONSTRUCTION - -#elif !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - -namespace boost { - namespace unordered { - namespace detail { - namespace func { - template - inline void construct_value(T* address, BOOST_FWD_REF(Args)... args) - { - new ((void*)address) T(boost::forward(args)...); - } - } // namespace func - } // namespace detail - } // namespace unordered -} // namespace boost - -#else - -namespace boost { - namespace unordered { - namespace detail { - namespace func { - template inline void construct_value(T* address) - { - new ((void*)address) T(); - } - - template - inline void construct_value(T* address, BOOST_FWD_REF(A0) a0) - { - new ((void*)address) T(boost::forward(a0)); - } - } // namespace func - } // namespace detail - } // namespace unordered -} // namespace boost - -#endif - //////////////////////////////////////////////////////////////////////////// // Construct from tuple // @@ -620,37 +567,6 @@ namespace boost { #endif -// construct_from_tuple for std::tuple - -#if !BOOST_UNORDERED_CXX11_CONSTRUCTION && BOOST_UNORDERED_TUPLE_ARGS - -namespace boost { - namespace unordered { - namespace detail { - namespace func { - template - void construct_from_tuple(Alloc&, T* ptr, std::tuple<>) - { - new ((void*)ptr) T(); - } - - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 1, std) - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 2, std) - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 3, std) - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 4, std) - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 5, std) - -#if BOOST_UNORDERED_TUPLE_ARGS >= 6 - BOOST_PP_REPEAT_FROM_TO(6, BOOST_PP_INC(BOOST_UNORDERED_TUPLE_ARGS), - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE, std) -#endif - } // namespace func - } // namespace detail - } // namespace unordered -} // namespace boost - -#endif - #undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE #undef BOOST_UNORDERED_GET_TUPLE_ARG @@ -741,8 +657,6 @@ namespace boost { }; }; -#if BOOST_UNORDERED_CXX11_CONSTRUCTION - //////////////////////////////////////////////////////////////////////// // Construct from variadic parameters @@ -816,124 +730,6 @@ namespace boost { boost::allocator_construct(alloc, address, std::piecewise_construct, to_std_tuple(a1), to_std_tuple(a2)); } - -#elif !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - - //////////////////////////////////////////////////////////////////////// - // Construct from variadic parameters - - template - inline void construct_from_args( - Alloc&, T* address, BOOST_FWD_REF(Args)... args) - { - new ((void*)address) T(boost::forward(args)...); - } - - // Special case for piecewise_construct - - template - inline typename enable_if, void>::type - construct_from_args(Alloc& alloc, std::pair* address, - BOOST_FWD_REF(A0), BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) - { - boost::unordered::detail::func::construct_from_tuple( - alloc, boost::addressof(address->first), boost::forward(a1)); - BOOST_TRY - { - boost::unordered::detail::func::construct_from_tuple( - alloc, boost::addressof(address->second), boost::forward(a2)); - } - BOOST_CATCH(...) - { - boost::unordered::detail::func::destroy( - boost::addressof(address->first)); - BOOST_RETHROW - } - BOOST_CATCH_END - } - -#else // BOOST_NO_CXX11_VARIADIC_TEMPLATES - - //////////////////////////////////////////////////////////////////////// - // Construct from emplace_args - - // Explicitly write out first three overloads for the sake of sane - // error messages. - - template - inline void construct_from_args( - Alloc&, T* address, emplace_args1 const& args) - { - new ((void*)address) T(boost::forward(args.a0)); - } - - template - inline void construct_from_args( - Alloc&, T* address, emplace_args2 const& args) - { - new ((void*)address) - T(boost::forward(args.a0), boost::forward(args.a1)); - } - - template - inline void construct_from_args( - Alloc&, T* address, emplace_args3 const& args) - { - new ((void*)address) T(boost::forward(args.a0), - boost::forward(args.a1), boost::forward(args.a2)); - } - - // Use a macro for the rest. - -#define BOOST_UNORDERED_CONSTRUCT_IMPL(z, num_params, _) \ - template \ - inline void construct_from_args(Alloc&, T* address, \ - boost::unordered::detail::BOOST_PP_CAT(emplace_args, num_params) < \ - BOOST_PP_ENUM_PARAMS_Z(z, num_params, A) > const& args) \ - { \ - new ((void*)address) \ - T(BOOST_PP_ENUM_##z(num_params, BOOST_UNORDERED_CALL_FORWARD, args.a)); \ - } - - BOOST_UNORDERED_CONSTRUCT_IMPL(1, 4, _) - BOOST_UNORDERED_CONSTRUCT_IMPL(1, 5, _) - BOOST_UNORDERED_CONSTRUCT_IMPL(1, 6, _) - BOOST_UNORDERED_CONSTRUCT_IMPL(1, 7, _) - BOOST_UNORDERED_CONSTRUCT_IMPL(1, 8, _) - BOOST_UNORDERED_CONSTRUCT_IMPL(1, 9, _) - BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT), - BOOST_UNORDERED_CONSTRUCT_IMPL, _) - -#undef BOOST_UNORDERED_CONSTRUCT_IMPL - - // Construct with piecewise_construct - - template - inline typename enable_if, void>::type - construct_from_args(Alloc& alloc, std::pair* address, - boost::unordered::detail::emplace_args3 const& args) - { - boost::unordered::detail::func::construct_from_tuple( - alloc, boost::addressof(address->first), args.a1); - BOOST_TRY - { - boost::unordered::detail::func::construct_from_tuple( - alloc, boost::addressof(address->second), args.a2); - } - BOOST_CATCH(...) - { - boost::unordered::detail::func::destroy( - boost::addressof(address->first)); - BOOST_RETHROW - } - BOOST_CATCH_END - } - -#endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES } // namespace func } // namespace detail } // namespace unordered @@ -1075,8 +871,6 @@ namespace boost { return a.release(); } -#if BOOST_UNORDERED_CXX11_CONSTRUCTION - template inline typename boost::allocator_pointer::type construct_node_pair(Alloc& alloc, BOOST_FWD_REF(Key) k) @@ -1135,108 +929,14 @@ namespace boost { value_allocator val_alloc(alloc); -#if !(BOOST_COMP_CLANG && BOOST_COMP_CLANG < BOOST_VERSION_NUMBER(3, 8, 0) && \ - defined(BOOST_LIBSTDCXX11)) boost::allocator_construct(val_alloc, a.node_->value_ptr(), std::piecewise_construct, std::forward_as_tuple(boost::forward(k)), std::forward_as_tuple(boost::forward(args)...)); -#else - // It doesn't seem to be possible to construct a tuple with 3 variadic - // rvalue reference members when using older versions of clang with - // libstdc++, so just use std::make_tuple instead of - // std::forward_as_tuple. - boost::allocator_construct(val_alloc, a.node_->value_ptr(), - std::piecewise_construct, - std::forward_as_tuple(boost::forward(k)), - std::make_tuple(boost::forward(args)...)); -#endif + return a.release(); } -#else - - template - inline - typename boost::unordered::detail::allocator_traits::pointer - construct_node_pair(Alloc& alloc, BOOST_FWD_REF(Key) k) - { - node_constructor a(alloc); - a.create_node(); - boost::unordered::detail::func::construct_value( - boost::addressof(a.node_->value_ptr()->first), - boost::forward(k)); - BOOST_TRY - { - boost::unordered::detail::func::construct_value( - boost::addressof(a.node_->value_ptr()->second)); - } - BOOST_CATCH(...) - { - boost::unordered::detail::func::destroy( - boost::addressof(a.node_->value_ptr()->first)); - BOOST_RETHROW - } - BOOST_CATCH_END - return a.release(); - } - - template - inline - typename boost::unordered::detail::allocator_traits::pointer - construct_node_pair( - Alloc& alloc, BOOST_FWD_REF(Key) k, BOOST_FWD_REF(Mapped) m) - { - node_constructor a(alloc); - a.create_node(); - boost::unordered::detail::func::construct_value( - boost::addressof(a.node_->value_ptr()->first), - boost::forward(k)); - BOOST_TRY - { - boost::unordered::detail::func::construct_value( - boost::addressof(a.node_->value_ptr()->second), - boost::forward(m)); - } - BOOST_CATCH(...) - { - boost::unordered::detail::func::destroy( - boost::addressof(a.node_->value_ptr()->first)); - BOOST_RETHROW - } - BOOST_CATCH_END - return a.release(); - } - - template - inline - typename boost::unordered::detail::allocator_traits::pointer - construct_node_pair_from_args( - Alloc& alloc, BOOST_FWD_REF(Key) k, Args&&... args) - { - node_constructor a(alloc); - a.create_node(); - boost::unordered::detail::func::construct_value( - boost::addressof(a.node_->value_ptr()->first), - boost::forward(k)); - BOOST_TRY - { - boost::unordered::detail::func::construct_from_args(alloc, - boost::addressof(a.node_->value_ptr()->second), - std::forward(args)...); - } - BOOST_CATCH(...) - { - boost::unordered::detail::func::destroy( - boost::addressof(a.node_->value_ptr()->first)); - BOOST_RETHROW - } - BOOST_CATCH_END - return a.release(); - } - -#endif - template inline typename boost::allocator_pointer::type construct_node_from_key(T*, Alloc& alloc, BOOST_FWD_REF(Key) k) diff --git a/test/helpers/test.hpp b/test/helpers/test.hpp index 3417178d..8b2cf623 100644 --- a/test/helpers/test.hpp +++ b/test/helpers/test.hpp @@ -138,8 +138,6 @@ namespace test { << BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT << "\n" \ << "BOOST_UNORDERED_EMPLACE_LIMIT: " << BOOST_UNORDERED_EMPLACE_LIMIT \ << "\n" \ - << "BOOST_UNORDERED_CXX11_CONSTRUCTION: " \ - << BOOST_UNORDERED_CXX11_CONSTRUCTION << "\n\n" \ << std::flush; \ } diff --git a/test/objects/test.hpp b/test/objects/test.hpp index bb2b2896..97914909 100644 --- a/test/objects/test.hpp +++ b/test/objects/test.hpp @@ -410,7 +410,6 @@ namespace test { ::operator delete((void*)p); } -#if BOOST_UNORDERED_CXX11_CONSTRUCTION template void construct(U* p, Args&&... args) { detail::tracker.track_construct((void*)p, sizeof(U), tag_); @@ -425,22 +424,6 @@ namespace test { // Work around MSVC buggy unused parameter warning. ignore_variable(&p); } -#else - private: - // I'm going to claim in the documentation that construct/destroy - // is never used when C++11 support isn't available, so might as - // well check that in the text. - // TODO: Or maybe just disallow them for values? - template void construct(U* p); - template void construct(U* p, A0 const&); - template - void construct(U* p, A0 const&, A1 const&); - template - void construct(U* p, A0 const&, A1 const&, A2 const&); - template void destroy(U* p); - - public: -#endif bool operator==(allocator1 const& x) const { return tag_ == x.tag_; }