Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86733 - in trunk/boost: graph/detail pending
From: jewillco_at_[hidden]
Date: 2013-11-16 21:18:42


Author: jewillco
Date: 2013-11-16 21:18:42 EST (Sat, 16 Nov 2013)
New Revision: 86733
URL: http://svn.boost.org/trac/boost/changeset/86733

Log:
Changed to use unique_ptr when C++11 is enabled; made other fixes to enable move semantics

Text files modified:
   trunk/boost/graph/detail/adjacency_list.hpp | 30 ++++++++++++++++++++++++++++--
   trunk/boost/pending/container_traits.hpp | 32 ++++++++++++++++++++++----------
   2 files changed, 50 insertions(+), 12 deletions(-)

Modified: trunk/boost/graph/detail/adjacency_list.hpp
==============================================================================
--- trunk/boost/graph/detail/adjacency_list.hpp Sat Nov 16 19:32:28 2013 (r86732)
+++ trunk/boost/graph/detail/adjacency_list.hpp 2013-11-16 21:18:42 EST (Sat, 16 Nov 2013) (r86733)
@@ -38,6 +38,12 @@
 #include <boost/static_assert.hpp>
 #include <boost/assert.hpp>
 
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+#define BOOST_GRAPH_MOVE_IF_POSSIBLE(x) (x)
+#else
+#define BOOST_GRAPH_MOVE_IF_POSSIBLE(x) (std::move((x)))
+#endif
+
 /*
   Outline for this file:
 
@@ -251,6 +257,7 @@
     template <class Vertex>
     no_property stored_edge<Vertex>::s_prop;
 
+#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
     template <class Vertex, class Property>
     class stored_edge_property : public stored_edge<Vertex> {
       typedef stored_edge_property self;
@@ -277,6 +284,25 @@
       // a perfect fit for the job, but it is darn close.
       std::auto_ptr<Property> m_property;
     };
+#else
+ template <class Vertex, class Property>
+ class stored_edge_property : public stored_edge<Vertex> {
+ typedef stored_edge_property self;
+ typedef stored_edge<Vertex> Base;
+ public:
+ typedef Property property_type;
+ inline stored_edge_property() { }
+ inline stored_edge_property(Vertex target,
+ const Property& p = Property())
+ : stored_edge<Vertex>(target), m_property(new Property(p)) { }
+ stored_edge_property(self&& x) = default;
+ self& operator=(self&& x) = default;
+ inline Property& get_property() { return *m_property; }
+ inline const Property& get_property() const { return *m_property; }
+ protected:
+ std::unique_ptr<Property> m_property;
+ };
+#endif
 
 
     template <class Vertex, class Iter, class Property>
@@ -384,7 +410,7 @@
         if (first != last)
           for (++i; i != last; ++i)
             if (!pred(*i)) {
- *first.base() = *i.base();
+ *first.base() = BOOST_GRAPH_MOVE_IF_POSSIBLE(*i.base());
               ++first;
             }
         el.erase(first.base(), el.end());
@@ -432,7 +458,7 @@
               self_loop_removed = false;
             }
             else if (!pred(*i)) {
- *first.base() = *i.base();
+ *first.base() = BOOST_GRAPH_MOVE_IF_POSSIBLE(*i.base());
               ++first;
             } else {
               if (source(*i, g) == target(*i, g)) self_loop_removed = true;

Modified: trunk/boost/pending/container_traits.hpp
==============================================================================
--- trunk/boost/pending/container_traits.hpp Sat Nov 16 19:32:28 2013 (r86732)
+++ trunk/boost/pending/container_traits.hpp 2013-11-16 21:18:42 EST (Sat, 16 Nov 2013) (r86733)
@@ -15,6 +15,7 @@
 #include <boost/next_prior.hpp>
 
 #include <algorithm> // for std::remove
+#include <utility>
 #include <vector>
 #include <list>
 #include <map>
@@ -38,6 +39,14 @@
 #include <unordered_map>
 #endif
 
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+#define BOOST_PENDING_FWD_TYPE(type) const type&
+#define BOOST_PENDING_FWD_VALUE(type, var) (var)
+#else
+#define BOOST_PENDING_FWD_TYPE(type) type&&
+#define BOOST_PENDING_FWD_VALUE(type, var) (std::forward<type>((var)))
+#endif
+
 // The content of this file is in 'graph_detail' because otherwise
 // there will be name clashes with
 // sandbox/boost/sequence_algo/container_traits.hpp
@@ -484,41 +493,41 @@
   // Push
   template <class Container, class T>
   std::pair<typename Container::iterator, bool>
- push_dispatch(Container& c, const T& v, back_insertion_sequence_tag)
+ push_dispatch(Container& c, BOOST_PENDING_FWD_TYPE(T) v, back_insertion_sequence_tag)
   {
- c.push_back(v);
+ c.push_back(BOOST_PENDING_FWD_VALUE(T, v));
     return std::make_pair(boost::prior(c.end()), true);
   }
 
   template <class Container, class T>
   std::pair<typename Container::iterator, bool>
- push_dispatch(Container& c, const T& v, front_insertion_sequence_tag)
+ push_dispatch(Container& c, BOOST_PENDING_FWD_TYPE(T) v, front_insertion_sequence_tag)
   {
- c.push_front(v);
+ c.push_front(BOOST_PENDING_FWD_VALUE(T, v));
     return std::make_pair(c.begin(), true);
   }
 
   template <class AssociativeContainer, class T>
   std::pair<typename AssociativeContainer::iterator, bool>
- push_dispatch(AssociativeContainer& c, const T& v,
+ push_dispatch(AssociativeContainer& c, BOOST_PENDING_FWD_TYPE(T) v,
                 unique_associative_container_tag)
   {
- return c.insert(v);
+ return c.insert(BOOST_PENDING_FWD_VALUE(T, v));
   }
 
   template <class AssociativeContainer, class T>
   std::pair<typename AssociativeContainer::iterator, bool>
- push_dispatch(AssociativeContainer& c, const T& v,
+ push_dispatch(AssociativeContainer& c, BOOST_PENDING_FWD_TYPE(T) v,
                 multiple_associative_container_tag)
   {
- return std::make_pair(c.insert(v), true);
+ return std::make_pair(c.insert(BOOST_PENDING_FWD_VALUE(T, v)), true);
   }
 
   template <class Container, class T>
   std::pair<typename Container::iterator,bool>
- push(Container& c, const T& v)
+ push(Container& c, BOOST_PENDING_FWD_TYPE(T) v)
   {
- return push_dispatch(c, v, container_category(c));
+ return push_dispatch(c, BOOST_PENDING_FWD_VALUE(T, v), container_category(c));
   }
 
   // Find
@@ -615,4 +624,7 @@
 
 }} // namespace boost::graph_detail
 
+#undef BOOST_PENDING_FWD_TYPE
+#undef BOOST_PENDING_FWD_VALUE
+
 #endif // BOOST_GRAPH_DETAIL_CONTAINER_TRAITS_H


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