From e2e995938998a3c822a8b139c5d994f5c5333801 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 20 Apr 2017 22:59:00 +0100 Subject: [PATCH] Split up emplace and emplace_hint code Busywork I guess, but I think it's more readable this way. The emplace macros are still unreadable, but I think they're rarely used. Btw. a bit weird that clang format has removed the indentation on the '// emplace' comment, not sure why that is. --- include/boost/unordered/unordered_map.hpp | 150 +++++++++++++--------- include/boost/unordered/unordered_set.hpp | 143 +++++++++++++-------- 2 files changed, 177 insertions(+), 116 deletions(-) diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index 7233aa27..0a257b7e 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -234,18 +234,13 @@ template class unordered_map // emplace #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template std::pair emplace(BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } - template - iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) - { - return table_.emplace_hint(hint, boost::forward(args)...); - } - #else #if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) @@ -262,6 +257,46 @@ template class unordered_map return this->emplace(boost::move(v)); } +#endif + + template + std::pair emplace(BOOST_FWD_REF(A0) a0) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0))); + } + + template + std::pair emplace( + BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0), boost::forward(a1))); + } + + template + std::pair emplace( + BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0), boost::forward(a1), + boost::forward(a2))); + } + +#endif + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + template + iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) + { + return table_.emplace_hint(hint, boost::forward(args)...); + } + +#else + +#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + iterator emplace_hint(const_iterator hint, boost::unordered::detail::empty_emplace = boost::unordered::detail::empty_emplace(), @@ -272,13 +307,6 @@ template class unordered_map #endif - template - std::pair emplace(BOOST_FWD_REF(A0) a0) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0))); - } - template iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0) { @@ -287,14 +315,6 @@ template class unordered_map boost::forward(a0))); } - template - std::pair emplace( - BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0), boost::forward(a1))); - } - template iterator emplace_hint( const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) @@ -304,15 +324,6 @@ template class unordered_map boost::forward(a0), boost::forward(a1))); } - template - std::pair emplace( - BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0), boost::forward(a1), - boost::forward(a2))); - } - template iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) @@ -323,6 +334,10 @@ template class unordered_map boost::forward(a2))); } +#endif + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + #define BOOST_UNORDERED_EMPLACE(z, n, _) \ template \ std::pair emplace( \ @@ -971,16 +986,12 @@ template class unordered_multimap // emplace #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template iterator emplace(BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } - template - iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) - { - return table_.emplace_hint(hint, boost::forward(args)...); - } #else #if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) @@ -996,14 +1007,6 @@ template class unordered_multimap return this->emplace(boost::move(v)); } - iterator emplace_hint(const_iterator hint, - boost::unordered::detail::empty_emplace = - boost::unordered::detail::empty_emplace(), - value_type v = value_type()) - { - return this->emplace_hint(hint, boost::move(v)); - } - #endif template iterator emplace(BOOST_FWD_REF(A0) a0) @@ -1012,14 +1015,6 @@ template class unordered_multimap boost::forward(a0))); } - template - iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0) - { - return table_.emplace_hint( - hint, boost::unordered::detail::create_emplace_args( - boost::forward(a0))); - } - template iterator emplace(BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) { @@ -1027,15 +1022,6 @@ template class unordered_multimap boost::forward(a0), boost::forward(a1))); } - template - iterator emplace_hint( - const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) - { - return table_.emplace_hint( - hint, boost::unordered::detail::create_emplace_args( - boost::forward(a0), boost::forward(a1))); - } - template iterator emplace( BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) @@ -1045,6 +1031,46 @@ template class unordered_multimap boost::forward(a2))); } +#endif + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + template + iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) + { + return table_.emplace_hint(hint, boost::forward(args)...); + } + +#else + +#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + + iterator emplace_hint(const_iterator hint, + boost::unordered::detail::empty_emplace = + boost::unordered::detail::empty_emplace(), + value_type v = value_type()) + { + return this->emplace_hint(hint, boost::move(v)); + } + +#endif + + template + iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0) + { + return table_.emplace_hint( + hint, boost::unordered::detail::create_emplace_args( + boost::forward(a0))); + } + template + iterator emplace_hint( + const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) + { + return table_.emplace_hint( + hint, boost::unordered::detail::create_emplace_args( + boost::forward(a0), boost::forward(a1))); + } + template iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) @@ -1055,6 +1081,10 @@ template class unordered_multimap boost::forward(a2))); } +#endif + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + #define BOOST_UNORDERED_EMPLACE(z, n, _) \ template \ iterator emplace(BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \ diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index 0bc240c1..aee65b41 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -232,17 +232,13 @@ template class unordered_set // emplace #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template std::pair emplace(BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } - template - iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) - { - return table_.emplace_hint(hint, boost::forward(args)...); - } #else #if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) @@ -259,6 +255,46 @@ template class unordered_set return this->emplace(boost::move(v)); } +#endif + + template + std::pair emplace(BOOST_FWD_REF(A0) a0) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0))); + } + + template + std::pair emplace( + BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0), boost::forward(a1))); + } + + template + std::pair emplace( + BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0), boost::forward(a1), + boost::forward(a2))); + } + +#endif + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + template + iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) + { + return table_.emplace_hint(hint, boost::forward(args)...); + } + +#else + +#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + iterator emplace_hint(const_iterator hint, boost::unordered::detail::empty_emplace = boost::unordered::detail::empty_emplace(), @@ -269,13 +305,6 @@ template class unordered_set #endif - template - std::pair emplace(BOOST_FWD_REF(A0) a0) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0))); - } - template iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0) { @@ -284,14 +313,6 @@ template class unordered_set boost::forward(a0))); } - template - std::pair emplace( - BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0), boost::forward(a1))); - } - template iterator emplace_hint( const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) @@ -301,15 +322,6 @@ template class unordered_set boost::forward(a0), boost::forward(a1))); } - template - std::pair emplace( - BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0), boost::forward(a1), - boost::forward(a2))); - } - template iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) @@ -320,6 +332,10 @@ template class unordered_set boost::forward(a2))); } +#endif + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + #define BOOST_UNORDERED_EMPLACE(z, n, _) \ template \ std::pair emplace( \ @@ -703,11 +719,6 @@ template class unordered_multiset return table_.emplace(boost::forward(args)...); } - template - iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) - { - return table_.emplace_hint(hint, boost::forward(args)...); - } #else #if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) @@ -723,6 +734,44 @@ template class unordered_multiset return this->emplace(boost::move(v)); } +#endif + + template iterator emplace(BOOST_FWD_REF(A0) a0) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0))); + } + + template + iterator emplace(BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0), boost::forward(a1))); + } + + template + iterator emplace( + BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) + { + return table_.emplace(boost::unordered::detail::create_emplace_args( + boost::forward(a0), boost::forward(a1), + boost::forward(a2))); + } + +#endif + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + template + iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) + { + return table_.emplace_hint(hint, boost::forward(args)...); + } + +#else + +#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + iterator emplace_hint(const_iterator hint, boost::unordered::detail::empty_emplace = boost::unordered::detail::empty_emplace(), @@ -733,12 +782,6 @@ template class unordered_multiset #endif - template iterator emplace(BOOST_FWD_REF(A0) a0) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0))); - } - template iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0) { @@ -747,13 +790,6 @@ template class unordered_multiset boost::forward(a0))); } - template - iterator emplace(BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0), boost::forward(a1))); - } - template iterator emplace_hint( const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) @@ -763,15 +799,6 @@ template class unordered_multiset boost::forward(a0), boost::forward(a1))); } - template - iterator emplace( - BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) - { - return table_.emplace(boost::unordered::detail::create_emplace_args( - boost::forward(a0), boost::forward(a1), - boost::forward(a2))); - } - template iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) @@ -782,6 +809,10 @@ template class unordered_multiset boost::forward(a2))); } +#endif + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + #define BOOST_UNORDERED_EMPLACE(z, n, _) \ template \ iterator emplace(BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \