Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75744 - in trunk/boost/unordered: . detail
From: dnljms_at_[hidden]
Date: 2011-11-30 03:21:59


Author: danieljames
Date: 2011-11-30 03:21:58 EST (Wed, 30 Nov 2011)
New Revision: 75744
URL: http://svn.boost.org/trac/boost/changeset/75744

Log:
Unordered: `emplace` cleanup.

- Always construct iterator in detail for consistency.
- Move 0-argument emplace to start of overloads.
Text files modified:
   trunk/boost/unordered/detail/equivalent.hpp | 8 +-
   trunk/boost/unordered/unordered_map.hpp | 130 +++++++++++++++++++++------------------
   trunk/boost/unordered/unordered_set.hpp | 130 +++++++++++++++++++++------------------
   3 files changed, 142 insertions(+), 126 deletions(-)

Modified: trunk/boost/unordered/detail/equivalent.hpp
==============================================================================
--- trunk/boost/unordered/detail/equivalent.hpp (original)
+++ trunk/boost/unordered/detail/equivalent.hpp 2011-11-30 03:21:58 EST (Wed, 30 Nov 2011)
@@ -453,22 +453,22 @@
         }
 
 #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 <BOOST_UNORDERED_EMPLACE_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));
         }
 
         ////////////////////////////////////////////////////////////////////////

Modified: trunk/boost/unordered/unordered_map.hpp
==============================================================================
--- trunk/boost/unordered/unordered_map.hpp (original)
+++ trunk/boost/unordered/unordered_map.hpp 2011-11-30 03:21:58 EST (Wed, 30 Nov 2011)
@@ -218,10 +218,35 @@
         template <class... Args>
         iterator emplace_hint(const_iterator, Args&&... args)
         {
- return iterator(table_.emplace(std::forward<Args>(args)...).first);
+ return table_.emplace(std::forward<Args>(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<iterator, bool> 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 <typename A0>
         std::pair<iterator, bool> emplace(BOOST_FWD_REF(A0) a0)
         {
@@ -315,27 +340,6 @@
 
 #undef BOOST_UNORDERED_EMPLACE
 
-#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
-
- std::pair<iterator, bool> 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<iterator, bool> insert(value_type const& x)
@@ -657,30 +661,55 @@
         template <class... Args>
         iterator emplace(Args&&... args)
         {
- return iterator(table_.emplace(std::forward<Args>(args)...));
+ return table_.emplace(std::forward<Args>(args)...);
         }
 
         template <class... Args>
         iterator emplace_hint(const_iterator, Args&&... args)
         {
- return iterator(table_.emplace(std::forward<Args>(args)...));
+ return table_.emplace(std::forward<Args>(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 <typename A0>
         iterator emplace(BOOST_FWD_REF(A0) a0)
         {
- return iterator(table_.emplace(
+ return table_.emplace(
                 boost::unordered::detail::create_emplace_args(a0)
- ));
+ );
         }
 
         template <typename A0>
         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 <typename A0, typename A1>
@@ -688,9 +717,9 @@
             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 <typename A0, typename A1>
@@ -698,9 +727,9 @@
             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 <typename A0, typename A1, typename A2>
@@ -709,9 +738,9 @@
             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 <typename A0, typename A1, typename A2>
@@ -720,9 +749,9 @@
             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 @@
                     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 @@
                     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 @@
 
 #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)

Modified: trunk/boost/unordered/unordered_set.hpp
==============================================================================
--- trunk/boost/unordered/unordered_set.hpp (original)
+++ trunk/boost/unordered/unordered_set.hpp 2011-11-30 03:21:58 EST (Wed, 30 Nov 2011)
@@ -216,10 +216,35 @@
         template <class... Args>
         iterator emplace_hint(const_iterator, Args&&... args)
         {
- return iterator(table_.emplace(std::forward<Args>(args)...).first);
+ return table_.emplace(std::forward<Args>(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<iterator, bool> 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 <typename A0>
         std::pair<iterator, bool> emplace(BOOST_FWD_REF(A0) a0)
         {
@@ -313,27 +338,6 @@
 
 #undef BOOST_UNORDERED_EMPLACE
 
-#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
-
- std::pair<iterator, bool> 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<iterator, bool> insert(value_type const& x)
@@ -640,30 +644,55 @@
         template <class... Args>
         iterator emplace(Args&&... args)
         {
- return iterator(table_.emplace(std::forward<Args>(args)...));
+ return table_.emplace(std::forward<Args>(args)...);
         }
 
         template <class... Args>
         iterator emplace_hint(const_iterator, Args&&... args)
         {
- return iterator(table_.emplace(std::forward<Args>(args)...));
+ return table_.emplace(std::forward<Args>(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 <typename A0>
         iterator emplace(BOOST_FWD_REF(A0) a0)
         {
- return iterator(table_.emplace(
+ return table_.emplace(
                 boost::unordered::detail::create_emplace_args(a0)
- ));
+ );
         }
 
         template <typename A0>
         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 <typename A0, typename A1>
@@ -671,9 +700,9 @@
             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 <typename A0, typename A1>
@@ -681,9 +710,9 @@
             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 <typename A0, typename A1, typename A2>
@@ -692,9 +721,9 @@
             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 <typename A0, typename A1, typename A2>
@@ -703,9 +732,9 @@
             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, _) \
@@ -716,11 +745,11 @@
                     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 < \
@@ -731,11 +760,11 @@
                     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,
@@ -743,27 +772,6 @@
 
 #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 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
 
         iterator insert(value_type const& x)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk