From b0ee2b51167c52a14ae6cee96300e0b78c57a909 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Mon, 28 Aug 2023 13:46:53 -0700 Subject: [PATCH] Remove BOOST_UNORDERED_EMPLACE_TEMPLATE machinery --- .../boost/unordered/detail/implementation.hpp | 186 +++--------------- 1 file changed, 24 insertions(+), 162 deletions(-) diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index 5cf9c6b3..8e0e6e1d 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -360,136 +360,6 @@ namespace boost { } // namespace unordered } // namespace boost -//////////////////////////////////////////////////////////////////////////// -// emplace_args -// -// Either forwarding variadic arguments, or storing the arguments in -// emplace_args##n - -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - -#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename... Args -#define BOOST_UNORDERED_EMPLACE_ARGS BOOST_FWD_REF(Args)... args -#define BOOST_UNORDERED_EMPLACE_FORWARD boost::forward(args)... - -#else - -#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename Args -#define BOOST_UNORDERED_EMPLACE_ARGS Args const& args -#define BOOST_UNORDERED_EMPLACE_FORWARD args - -#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - -#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ - typedef BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(Arg, n); \ - BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n); - -#else - -#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ - typedef typename boost::add_lvalue_reference::type \ - BOOST_PP_CAT(Arg, n); \ - BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n); - -#endif - -#define BOOST_UNORDERED_FWD_PARAM(z, n, a) \ - BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(a, n) - -#define BOOST_UNORDERED_CALL_FORWARD(z, i, a) \ - boost::forward(BOOST_PP_CAT(a, i)) - -#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \ - BOOST_PP_CAT(a, n)(BOOST_PP_CAT(b, n)) - -#define BOOST_UNORDERED_EARGS(z, n, _) \ - template \ - struct BOOST_PP_CAT(emplace_args, n) \ - { \ - BOOST_PP_REPEAT_##z(n, BOOST_UNORDERED_EARGS_MEMBER, _) BOOST_PP_CAT( \ - emplace_args, n)(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, Arg, b)) \ - : BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_EARGS_INIT, _) \ - { \ - } \ - }; \ - \ - template \ - inline BOOST_PP_CAT(emplace_args, n) \ - create_emplace_args(BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, b)) \ - { \ - BOOST_PP_CAT(emplace_args, n) e( \ - BOOST_PP_ENUM_PARAMS_Z(z, n, b)); \ - return e; \ - } - -namespace boost { - namespace unordered { - namespace detail { - template struct emplace_args1 - { - BOOST_UNORDERED_EARGS_MEMBER(1, 0, _) - - explicit emplace_args1(Arg0 b0) : a0(b0) {} - }; - - template - inline emplace_args1 create_emplace_args(BOOST_FWD_REF(A0) b0) - { - emplace_args1 e(b0); - return e; - } - - template struct emplace_args2 - { - BOOST_UNORDERED_EARGS_MEMBER(1, 0, _) - BOOST_UNORDERED_EARGS_MEMBER(1, 1, _) - - emplace_args2(Arg0 b0, Arg1 b1) : a0(b0), a1(b1) {} - }; - - template - inline emplace_args2 create_emplace_args( - BOOST_FWD_REF(A0) b0, BOOST_FWD_REF(A1) b1) - { - emplace_args2 e(b0, b1); - return e; - } - - template struct emplace_args3 - { - BOOST_UNORDERED_EARGS_MEMBER(1, 0, _) - BOOST_UNORDERED_EARGS_MEMBER(1, 1, _) - BOOST_UNORDERED_EARGS_MEMBER(1, 2, _) - - emplace_args3(Arg0 b0, Arg1 b1, Arg2 b2) : a0(b0), a1(b1), a2(b2) {} - }; - - template - inline emplace_args3 create_emplace_args( - BOOST_FWD_REF(A0) b0, BOOST_FWD_REF(A1) b1, BOOST_FWD_REF(A2) b2) - { - emplace_args3 e(b0, b1, b2); - return e; - } - - BOOST_UNORDERED_EARGS(1, 4, _) - BOOST_UNORDERED_EARGS(1, 5, _) - BOOST_UNORDERED_EARGS(1, 6, _) - BOOST_UNORDERED_EARGS(1, 7, _) - BOOST_UNORDERED_EARGS(1, 8, _) - BOOST_UNORDERED_EARGS(1, 9, _) - BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT), - BOOST_UNORDERED_EARGS, _) - } // namespace detail - } // namespace unordered -} // namespace boost - -#undef BOOST_UNORDERED_DEFINE_EMPLACE_ARGS -#undef BOOST_UNORDERED_EARGS_MEMBER -#undef BOOST_UNORDERED_EARGS_INIT - -#endif - //////////////////////////////////////////////////////////////////////////////// // // Some utilities for implementing allocator_traits, but useful elsewhere so @@ -1197,9 +1067,9 @@ namespace boost { // Some nicer construct_node functions, might try to // improve implementation later. - template + template inline typename boost::allocator_pointer::type - construct_node_from_args(Alloc& alloc, BOOST_UNORDERED_EMPLACE_ARGS) + construct_node_from_args(Alloc& alloc, Args&&... args) { typedef typename boost::allocator_value_type::type node; typedef typename node::value_type value_type; @@ -1211,7 +1081,7 @@ namespace boost { node_constructor a(alloc); a.create_node(); construct_from_args( - val_alloc, a.node_->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD); + val_alloc, a.node_->value_ptr(), std::forward(args)...); return a.release(); } @@ -1367,12 +1237,11 @@ namespace boost { return a.release(); } - template + template inline typename boost::unordered::detail::allocator_traits::pointer construct_node_pair_from_args( - Alloc& alloc, BOOST_FWD_REF(Key) k, BOOST_UNORDERED_EMPLACE_ARGS) + Alloc& alloc, BOOST_FWD_REF(Key) k, Args&&... args) { node_constructor a(alloc); a.create_node(); @@ -1383,7 +1252,7 @@ namespace boost { { boost::unordered::detail::func::construct_from_args(alloc, boost::addressof(a.node_->value_ptr()->second), - BOOST_UNORDERED_EMPLACE_FORWARD); + std::forward(args)...); } BOOST_CATCH(...) { @@ -2477,20 +2346,19 @@ namespace boost { // Emplace/Insert - template + template iterator emplace_hint_unique( - c_iterator hint, const_key_type& k, BOOST_UNORDERED_EMPLACE_ARGS) + c_iterator hint, const_key_type& k, Args&&... args) { if (hint.p && this->key_eq()(k, this->get_key(hint.p))) { return iterator(hint.p, hint.itb); } else { - return emplace_unique(k, BOOST_UNORDERED_EMPLACE_FORWARD).first; + return emplace_unique(k, std::forward(args)...).first; } } - template - emplace_return emplace_unique( - const_key_type& k, BOOST_UNORDERED_EMPLACE_ARGS) + template + emplace_return emplace_unique(const_key_type& k, Args&&... args) { std::size_t key_hash = this->hash(k); bucket_iterator itb = buckets_.at(buckets_.position(key_hash)); @@ -2500,7 +2368,7 @@ namespace boost { return emplace_return(iterator(pos, itb), false); } else { node_tmp b(boost::unordered::detail::func::construct_node_from_args( - this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD), + this->node_alloc(), std::forward(args)...), this->node_alloc()); if (size_ + 1 > max_load_) { @@ -2516,12 +2384,11 @@ namespace boost { } } - template - iterator emplace_hint_unique( - c_iterator hint, no_key, BOOST_UNORDERED_EMPLACE_ARGS) + template + iterator emplace_hint_unique(c_iterator hint, no_key, Args&&... args) { node_tmp b(boost::unordered::detail::func::construct_node_from_args( - this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD), + this->node_alloc(), std::forward(args)...), this->node_alloc()); const_key_type& k = this->get_key(b.node_); @@ -2548,11 +2415,11 @@ namespace boost { return iterator(p, itb); } - template - emplace_return emplace_unique(no_key, BOOST_UNORDERED_EMPLACE_ARGS) + template + emplace_return emplace_unique(no_key, Args&&... args) { node_tmp b(boost::unordered::detail::func::construct_node_from_args( - this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD), + this->node_alloc(), std::forward(args)...), this->node_alloc()); const_key_type& k = this->get_key(b.node_); @@ -2619,9 +2486,8 @@ namespace boost { } } - template - emplace_return try_emplace_unique( - BOOST_FWD_REF(Key) k, BOOST_UNORDERED_EMPLACE_ARGS) + template + emplace_return try_emplace_unique(BOOST_FWD_REF(Key) k, Args&&... args) { std::size_t key_hash = this->hash(k); bucket_iterator itb = buckets_.at(buckets_.position(key_hash)); @@ -2634,7 +2500,7 @@ namespace boost { node_tmp b( boost::unordered::detail::func::construct_node_pair_from_args( - this->node_alloc(), k, BOOST_UNORDERED_EMPLACE_FORWARD), + this->node_alloc(), k, std::forward(args)...), this->node_alloc()); if (size_ + 1 > max_load_) { @@ -2649,14 +2515,14 @@ namespace boost { return emplace_return(iterator(pos, itb), true); } - template + template iterator try_emplace_hint_unique( - c_iterator hint, BOOST_FWD_REF(Key) k, BOOST_UNORDERED_EMPLACE_ARGS) + c_iterator hint, BOOST_FWD_REF(Key) k, Args&&... args) { if (hint.p && this->key_eq()(hint->first, k)) { return iterator(hint.p, hint.itb); } else { - return try_emplace_unique(k, BOOST_UNORDERED_EMPLACE_FORWARD).first; + return try_emplace_unique(k, std::forward(args)...).first; } } @@ -3611,8 +3477,4 @@ namespace boost { } // namespace unordered } // namespace boost -#undef BOOST_UNORDERED_EMPLACE_TEMPLATE -#undef BOOST_UNORDERED_EMPLACE_ARGS -#undef BOOST_UNORDERED_EMPLACE_FORWARD - #endif