diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index 57ddbec9..6e7e4190 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -453,22 +453,22 @@ namespace boost { namespace unordered { namespace detail { } #if defined(BOOST_NO_RVALUE_REFERENCES) - node_pointer emplace(boost::unordered::detail::emplace_args1< + iterator emplace(boost::unordered::detail::emplace_args1< boost::unordered::detail::please_ignore_this_overload> const&) { BOOST_ASSERT(false); - return this->begin(); + return iterator(); } #endif template - node_pointer emplace(BOOST_UNORDERED_EMPLACE_ARGS) + iterator emplace(BOOST_UNORDERED_EMPLACE_ARGS) { node_constructor a(this->node_alloc()); a.construct_node(); a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD); - return emplace_impl(a); + return iterator(emplace_impl(a)); } //////////////////////////////////////////////////////////////////////// diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index 5c85ed7e..61025fd4 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -218,10 +218,35 @@ namespace unordered template iterator emplace_hint(const_iterator, Args&&... args) { - return iterator(table_.emplace(std::forward(args)...).first); + return table_.emplace(std::forward(args)...).first; } #else +#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + + // 0 argument emplace requires special treatment in case + // the container is instantiated with a value type that + // doesn't have a default constructor. + + std::pair emplace( + boost::unordered::detail::empty_emplace + = boost::unordered::detail::empty_emplace(), + value_type v = value_type()) + { + 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 std::pair emplace(BOOST_FWD_REF(A0) a0) { @@ -315,27 +340,6 @@ namespace unordered #undef BOOST_UNORDERED_EMPLACE -#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) - - std::pair emplace( - boost::unordered::detail::empty_emplace - = boost::unordered::detail::empty_emplace(), - value_type v = value_type()) - { - 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 - #endif std::pair insert(value_type const& x) @@ -657,30 +661,55 @@ namespace unordered template iterator emplace(Args&&... args) { - return iterator(table_.emplace(std::forward(args)...)); + return table_.emplace(std::forward(args)...); } template iterator emplace_hint(const_iterator, Args&&... args) { - return iterator(table_.emplace(std::forward(args)...)); + return table_.emplace(std::forward(args)...); } #else +#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + + // 0 argument emplace requires special treatment in case + // the container is instantiated with a value type that + // doesn't have a default constructor. + + iterator emplace( + boost::unordered::detail::empty_emplace + = boost::unordered::detail::empty_emplace(), + value_type v = value_type()) + { + 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) { - return iterator(table_.emplace( + return table_.emplace( boost::unordered::detail::create_emplace_args(a0) - )); + ); } template iterator emplace_hint(const_iterator, BOOST_FWD_REF(A0) a0) { - return iterator(table_.emplace( + return table_.emplace( boost::unordered::detail::create_emplace_args(a0) - )); + ); } template @@ -688,9 +717,9 @@ namespace unordered BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) { - return iterator(table_.emplace( + return table_.emplace( boost::unordered::detail::create_emplace_args(a0, a1) - )); + ); } template @@ -698,9 +727,9 @@ namespace unordered BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1) { - return iterator(table_.emplace( + return table_.emplace( boost::unordered::detail::create_emplace_args(a0, a1) - )); + ); } template @@ -709,9 +738,9 @@ namespace unordered BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) { - return iterator(table_.emplace( + return table_.emplace( boost::unordered::detail::create_emplace_args(a0, a1, a2) - )); + ); } template @@ -720,9 +749,9 @@ namespace unordered BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2) { - return iterator(table_.emplace( + return table_.emplace( boost::unordered::detail::create_emplace_args(a0, a1, a2) - )); + ); } #define BOOST_UNORDERED_EMPLACE(z, n, _) \ @@ -733,11 +762,11 @@ namespace unordered BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \ ) \ { \ - return iterator(table_.emplace( \ + return table_.emplace( \ boost::unordered::detail::create_emplace_args( \ BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \ a) \ - ))); \ + )); \ } \ \ template < \ @@ -748,11 +777,11 @@ namespace unordered BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \ ) \ { \ - return iterator(table_.emplace( \ + return table_.emplace( \ boost::unordered::detail::create_emplace_args( \ BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \ a) \ - ))); \ + )); \ } BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, @@ -760,27 +789,6 @@ namespace unordered #undef BOOST_UNORDERED_EMPLACE -#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) - - iterator emplace( - boost::unordered::detail::empty_emplace - = boost::unordered::detail::empty_emplace(), - value_type v = value_type()) - { - return iterator(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 iterator(this->emplace_hint(hint, boost::move(v))); - } - -#endif - #endif iterator insert(value_type const& x) diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index bfcd27a3..3f3ed6ba 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -216,10 +216,35 @@ namespace unordered template iterator emplace_hint(const_iterator, Args&&... args) { - return iterator(table_.emplace(std::forward(args)...).first); + return table_.emplace(std::forward(args)...).first; } #else +#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + + // 0 argument emplace requires special treatment in case + // the container is instantiated with a value type that + // doesn't have a default constructor. + + std::pair emplace( + boost::unordered::detail::empty_emplace + = boost::unordered::detail::empty_emplace(), + value_type v = value_type()) + { + 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 std::pair emplace(BOOST_FWD_REF(A0) a0) { @@ -313,27 +338,6 @@ namespace unordered #undef BOOST_UNORDERED_EMPLACE -#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) - - std::pair emplace( - boost::unordered::detail::empty_emplace - = boost::unordered::detail::empty_emplace(), - value_type v = value_type()) - { - 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 iterator(this->emplace_hint(hint, boost::move(v))); - } - -#endif - #endif std::pair insert(value_type const& x) @@ -640,111 +644,22 @@ namespace unordered template iterator emplace(Args&&... args) { - return iterator(table_.emplace(std::forward(args)...)); + return table_.emplace(std::forward(args)...); } template iterator emplace_hint(const_iterator, Args&&... args) { - return iterator(table_.emplace(std::forward(args)...)); + return table_.emplace(std::forward(args)...); } #else - template - iterator emplace(BOOST_FWD_REF(A0) a0) - { - return iterator(table_.emplace( - boost::unordered::detail::create_emplace_args(a0) - )); - } - - template - iterator emplace_hint(const_iterator, BOOST_FWD_REF(A0) a0) - { - return iterator(table_.emplace( - boost::unordered::detail::create_emplace_args(a0) - )); - } - - template - iterator emplace( - BOOST_FWD_REF(A0) a0, - BOOST_FWD_REF(A1) a1) - { - return iterator(table_.emplace( - boost::unordered::detail::create_emplace_args(a0, a1) - )); - } - - template - iterator emplace_hint(const_iterator, - BOOST_FWD_REF(A0) a0, - BOOST_FWD_REF(A1) a1) - { - return iterator(table_.emplace( - boost::unordered::detail::create_emplace_args(a0, a1) - )); - } - - template - iterator emplace( - BOOST_FWD_REF(A0) a0, - BOOST_FWD_REF(A1) a1, - BOOST_FWD_REF(A2) a2) - { - return iterator(table_.emplace( - boost::unordered::detail::create_emplace_args(a0, a1, a2) - )); - } - - template - iterator emplace_hint(const_iterator, - BOOST_FWD_REF(A0) a0, - BOOST_FWD_REF(A1) a1, - BOOST_FWD_REF(A2) a2) - { - return iterator(table_.emplace( - boost::unordered::detail::create_emplace_args(a0, a1, a2) - )); - } - -#define BOOST_UNORDERED_EMPLACE(z, n, _) \ - template < \ - BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \ - > \ - iterator emplace( \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \ - ) \ - { \ - return iterator(table_.emplace( \ - boost::unordered::detail::create_emplace_args( \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \ - a) \ - ))); \ - } \ - \ - template < \ - BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \ - > \ - iterator emplace_hint( \ - const_iterator, \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \ - ) \ - { \ - return iterator(table_.emplace( \ - boost::unordered::detail::create_emplace_args( \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \ - a) \ - ))); \ - } - - BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, - BOOST_UNORDERED_EMPLACE, _) - -#undef BOOST_UNORDERED_EMPLACE - #if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) + // 0 argument emplace requires special treatment in case + // the container is instantiated with a value type that + // doesn't have a default constructor. + iterator emplace( boost::unordered::detail::empty_emplace = boost::unordered::detail::empty_emplace(), @@ -764,6 +679,99 @@ namespace unordered #endif + template + iterator emplace(BOOST_FWD_REF(A0) a0) + { + return table_.emplace( + boost::unordered::detail::create_emplace_args(a0) + ); + } + + template + iterator emplace_hint(const_iterator, BOOST_FWD_REF(A0) a0) + { + return table_.emplace( + boost::unordered::detail::create_emplace_args(a0) + ); + } + + template + iterator emplace( + BOOST_FWD_REF(A0) a0, + BOOST_FWD_REF(A1) a1) + { + return table_.emplace( + boost::unordered::detail::create_emplace_args(a0, a1) + ); + } + + template + iterator emplace_hint(const_iterator, + BOOST_FWD_REF(A0) a0, + BOOST_FWD_REF(A1) a1) + { + return table_.emplace( + boost::unordered::detail::create_emplace_args(a0, 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(a0, a1, a2) + ); + } + + template + iterator emplace_hint(const_iterator, + BOOST_FWD_REF(A0) a0, + BOOST_FWD_REF(A1) a1, + BOOST_FWD_REF(A2) a2) + { + return table_.emplace( + boost::unordered::detail::create_emplace_args(a0, a1, a2) + ); + } + +#define BOOST_UNORDERED_EMPLACE(z, n, _) \ + template < \ + BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \ + > \ + iterator emplace( \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \ + ) \ + { \ + return table_.emplace( \ + boost::unordered::detail::create_emplace_args( \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \ + a) \ + )); \ + } \ + \ + template < \ + BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \ + > \ + iterator emplace_hint( \ + const_iterator, \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \ + ) \ + { \ + return table_.emplace( \ + boost::unordered::detail::create_emplace_args( \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \ + a) \ + )); \ + } + + BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, + BOOST_UNORDERED_EMPLACE, _) + +#undef BOOST_UNORDERED_EMPLACE + #endif iterator insert(value_type const& x)