Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85294 - trunk/libs/geometry/example
From: barend.gehrels_at_[hidden]
Date: 2013-08-10 18:18:27


Author: barendgehrels
Date: 2013-08-10 18:18:27 EDT (Sat, 10 Aug 2013)
New Revision: 85294
URL: http://svn.boost.org/trac/boost/changeset/85294

Log:
[geometry] fixed c08 example w.r.t. iterators

Text files modified:
   trunk/libs/geometry/example/c08_custom_non_std_example.cpp | 68 +++++++++++++++++++++++++++------------
   1 files changed, 47 insertions(+), 21 deletions(-)

Modified: trunk/libs/geometry/example/c08_custom_non_std_example.cpp
==============================================================================
--- trunk/libs/geometry/example/c08_custom_non_std_example.cpp Sat Aug 10 17:46:01 2013 (r85293)
+++ trunk/libs/geometry/example/c08_custom_non_std_example.cpp 2013-08-10 18:18:27 EDT (Sat, 10 Aug 2013) (r85294)
@@ -65,41 +65,59 @@
 // Adaption: implement iterator and range-extension, and register with Boost.Geometry
 
 // 1) implement iterator (const and non-const versions)
-template <bool IsConst>
+template<typename MyPolygon>
 struct custom_iterator : public boost::iterator_facade
                             <
- custom_iterator<IsConst>,
+ custom_iterator<MyPolygon>,
                                 my_point,
                                 boost::random_access_traversal_tag,
- typename boost::geometry::add_const_if_c<IsConst, my_point>::type&
+ typename boost::mpl::if_
+ <
+ boost::is_const<MyPolygon>,
+ my_point const,
+ my_point
+ >::type&
>
 {
     // Constructor for begin()
- explicit custom_iterator(typename boost::geometry::add_const_if_c<IsConst, my_polygon>::type& polygon)
+ explicit custom_iterator(MyPolygon& polygon)
         : m_polygon(&polygon)
         , m_index(0)
     {}
 
     // Constructor for end()
- explicit custom_iterator(bool, typename boost::geometry::add_const_if_c<IsConst, my_polygon>::type& polygon)
+ explicit custom_iterator(bool, MyPolygon& polygon)
         : m_polygon(&polygon)
         , m_index(polygon.point_count())
     {}
 
 
+ // Default constructor
+ explicit custom_iterator()
+ : m_polygon(NULL)
+ , m_index(-1)
+ {}
+
+ typedef typename boost::mpl::if_
+ <
+ boost::is_const<MyPolygon>,
+ my_point const,
+ my_point
+ >::type my_point_type;
 
 private:
     friend class boost::iterator_core_access;
 
+
     typedef boost::iterator_facade
         <
- custom_iterator<IsConst>,
+ custom_iterator<MyPolygon>,
             my_point,
             boost::random_access_traversal_tag,
- typename boost::geometry::add_const_if_c<IsConst, my_point>::type&
+ my_point_type&
> facade;
 
- typename boost::geometry::add_const_if_c<IsConst, my_polygon>::type* m_polygon;
+ MyPolygon* m_polygon;
     int m_index;
 
     bool equal(custom_iterator const& other) const
@@ -134,7 +152,7 @@
     }
 
     // const and non-const dereference of this iterator
- typename boost::geometry::add_const_if_c<IsConst, my_point>::type& dereference() const
+ my_point_type& dereference() const
     {
         return m_polygon->get_point(m_index);
     }
@@ -150,12 +168,12 @@
 {
     template<> struct range_mutable_iterator<my_polygon>
     {
- typedef custom_iterator<false> type;
+ typedef custom_iterator<my_polygon> type;
     };
 
     template<> struct range_const_iterator<my_polygon>
     {
- typedef custom_iterator<true> type;
+ typedef custom_iterator<my_polygon const> type;
     };
 
     // RangeEx
@@ -168,24 +186,24 @@
 
 
 // 2b) free-standing function for Boost.Range ADP
-inline custom_iterator<false> range_begin(my_polygon& polygon)
+inline custom_iterator<my_polygon> range_begin(my_polygon& polygon)
 {
- return custom_iterator<false>(polygon);
+ return custom_iterator<my_polygon>(polygon);
 }
 
-inline custom_iterator<true> range_begin(my_polygon const& polygon)
+inline custom_iterator<my_polygon const> range_begin(my_polygon const& polygon)
 {
- return custom_iterator<true>(polygon);
+ return custom_iterator<my_polygon const>(polygon);
 }
 
-inline custom_iterator<false> range_end(my_polygon& polygon)
+inline custom_iterator<my_polygon> range_end(my_polygon& polygon)
 {
- return custom_iterator<false>(true, polygon);
+ return custom_iterator<my_polygon>(true, polygon);
 }
 
-inline custom_iterator<true> range_end(my_polygon const& polygon)
+inline custom_iterator<my_polygon const> range_end(my_polygon const& polygon)
 {
- return custom_iterator<true>(true, polygon);
+ return custom_iterator<my_polygon const>(true, polygon);
 }
 
 
@@ -210,6 +228,14 @@
     }
 };
 
+template<> struct clear<my_polygon>
+{
+ static inline void apply(my_polygon& polygon)
+ {
+ polygon.erase_all();
+ }
+};
+
 }}}
 
 
@@ -225,8 +251,8 @@
 
 void walk_using_iterator(my_polygon const& polygon)
 {
- for (custom_iterator<true> it = custom_iterator<true>(polygon);
- it != custom_iterator<true>(true, polygon);
+ for (custom_iterator<my_polygon const> it = custom_iterator<my_polygon const>(polygon);
+ it != custom_iterator<my_polygon const>(true, polygon);
         ++it)
     {
         std::cout << boost::geometry::dsv(*it) << std::endl;


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