From 082adbb6554eb7ac295e30015c87db0c1549e948 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Sun, 6 Apr 2014 01:43:25 +0300 Subject: [PATCH 1/7] [point_iterator] fix errors and warnings for g++ and clang++ with C++11 enabled --- .../geometry/iterators/concatenate_iterator.hpp | 2 +- .../boost/geometry/iterators/flatten_iterator.hpp | 14 +++++++++++--- test/iterators/flatten_iterator.cpp | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/boost/geometry/iterators/concatenate_iterator.hpp b/include/boost/geometry/iterators/concatenate_iterator.hpp index 32a8b2332..3cad9b15a 100644 --- a/include/boost/geometry/iterators/concatenate_iterator.hpp +++ b/include/boost/geometry/iterators/concatenate_iterator.hpp @@ -23,7 +23,7 @@ namespace boost { namespace geometry template -struct concatenate_iterator +class concatenate_iterator : public boost::iterator_facade < concatenate_iterator, diff --git a/include/boost/geometry/iterators/flatten_iterator.hpp b/include/boost/geometry/iterators/flatten_iterator.hpp index 9e3983cc4..ae0145816 100644 --- a/include/boost/geometry/iterators/flatten_iterator.hpp +++ b/include/boost/geometry/iterators/flatten_iterator.hpp @@ -30,7 +30,7 @@ template typename AccessInnerBegin, typename AccessInnerEnd > -struct flatten_iterator +class flatten_iterator : public boost::iterator_facade < flatten_iterator @@ -83,9 +83,17 @@ public: OtherAccessInnerBegin, OtherAccessInnerEnd > const& other, - typename boost::enable_if + typename boost::enable_if_c < - boost::is_convertible, + boost::is_convertible + < + OtherOuterIterator, OuterIterator + >::value + && + boost::is_convertible + < + OtherInnerIterator, InnerIterator + >::value, enabler >::type = enabler()) : m_outer_it(other.m_outer_it), diff --git a/test/iterators/flatten_iterator.cpp b/test/iterators/flatten_iterator.cpp index 98e8643e2..03fde5182 100644 --- a/test/iterators/flatten_iterator.cpp +++ b/test/iterators/flatten_iterator.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include From ab5c78cec04eb834f5d765912deb959542627ff0 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 7 Apr 2014 11:19:45 +0300 Subject: [PATCH 2/7] [point iterator] minor stylistic fix --- test/iterators/flatten_iterator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/iterators/flatten_iterator.cpp b/test/iterators/flatten_iterator.cpp index 03fde5182..a0b5434f4 100644 --- a/test/iterators/flatten_iterator.cpp +++ b/test/iterators/flatten_iterator.cpp @@ -146,7 +146,7 @@ struct test_flatten_iterator { #ifdef GEOMETRY_TEST_DEBUG std::stringstream sstream; - sstream << case_id << " " << "[" << container_id << "]"; + sstream << case_id << " [" << container_id << "]"; std::cout << "case id: " << sstream.str() << std::endl; #endif From 2ea67309e7bc3634e850531c38686a680f602280 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 7 Apr 2014 11:22:07 +0300 Subject: [PATCH 3/7] [point iterator][concatenate iterator] make the unit test more elaborate: add tests for vector-vector and list-list container conbinations --- test/iterators/concatenate_iterator.cpp | 75 +++++++++++++++---------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/test/iterators/concatenate_iterator.cpp b/test/iterators/concatenate_iterator.cpp index 6a488bcde..8d88e2212 100644 --- a/test/iterators/concatenate_iterator.cpp +++ b/test/iterators/concatenate_iterator.cpp @@ -54,10 +54,14 @@ struct test_concatenate_iterator { template static inline void apply(Container1& c1, Container2& c2, - std::string const& case_id) + std::string const& case_id, + std::string const& containers_id) { #ifdef GEOMETRY_TEST_DEBUG - std::cout << "case id: " << case_id << std::endl; + std::stringstream sstream; + sstream << case_id << " [" << containers_id << "]"; + + std::cout << "case id: " << sstream.str() << std::endl; #endif typedef typename Container1::const_iterator const_iterator1; typedef typename Container2::const_iterator const_iterator2; @@ -146,6 +150,7 @@ struct test_concatenate_iterator std::max_element(const_begin, const_end); BOOST_CHECK( it_max == const_it_max ); + BOOST_CHECK( *it_max == *const_it_max ); value_type old_value = *const_begin; value_type new_value = *it_max + 1; @@ -181,6 +186,7 @@ struct test_concatenate_iterator std::max_element(const_begin, const_end); BOOST_CHECK( it_max == const_it_max ); + BOOST_CHECK( *it_max == *const_it_max ); value_type old_value = *begin2; value_type new_value = *it_max + 1; @@ -227,34 +233,45 @@ struct test_concatenate_iterator }; +template +void test_concatenation_of_containers(Container1& c1, Container2& c2, + std::string const& containers_id) +{ +#ifdef GEOMETRY_TEST_DEBUG + std::cout << std::endl << std::endl; + std::cout << "************************************" << std::endl + << " TESTING CONTAINERS COMBINATION: " + << containers_id << std::endl + << "************************************" << std::endl + << std::endl; +#endif + + c1.clear(); + c2.clear(); + test_concatenate_iterator::apply(c1, c2, "empty_both", containers_id); + + c2 += 10,11,12,13,14,15,16,17,18,19,20; + test_concatenate_iterator::apply(c1, c2, "empty_first", containers_id); + + c2.clear(); + c1 += 0,1,2,3,4,5,6; + test_concatenate_iterator::apply(c1, c2, "empty_second", containers_id); + + c1.clear(); + c2.clear(); + c1 += 0,1,2,3,4,5,6; + c2 += 10,11,12,13,14,15,16,17,18,19,20; + test_concatenate_iterator::apply(c1, c2, "non_empty", containers_id); +} + + BOOST_AUTO_TEST_CASE( test_concatenate_iterator_all ) { - { - std::vector v; - std::list l; + std::vector v, vv; + std::list l, ll; - test_concatenate_iterator::apply(v, l, "empty_both"); - } - { - std::vector v; - std::list l; - l += 10,11,12,13,14,15,16,17,18,19,20; - - test_concatenate_iterator::apply(v, l, "empty_first"); - } - { - std::vector v; - v += 0,1,2,3,4,5,6; - std::list l; - - test_concatenate_iterator::apply(v, l, "empty_second"); - } - { - std::vector v; - v += 0,1,2,3,4,5,6; - std::list l; - l += 10,11,12,13,14,15,16,17,18,19,20; - - test_concatenate_iterator::apply(l, v, "non_empty"); - } + test_concatenation_of_containers(v, vv, "VV"); + test_concatenation_of_containers(v, l, "VL"); + test_concatenation_of_containers(l, v, "LV"); + test_concatenation_of_containers(l, ll, "LL"); } From 457d22d0d90a1e26b83bc3e9e70407a39d00277c Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 7 Apr 2014 11:26:14 +0300 Subject: [PATCH 4/7] [point iterator] add tests for const/non-const iterator equality/inequality --- test/iterators/point_iterator.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/iterators/point_iterator.cpp b/test/iterators/point_iterator.cpp index 13d77fdf8..ec0f6bcf8 100644 --- a/test/iterators/point_iterator.cpp +++ b/test/iterators/point_iterator.cpp @@ -228,6 +228,15 @@ struct test_point_iterator_of_geometry const_begin = begin; const_end = end; + // testing equality/inequality comparison + BOOST_CHECK ( begin == const_begin ); + BOOST_CHECK ( end == const_end ); + if ( begin != end ) + { + BOOST_CHECK ( begin != const_end ); + BOOST_CHECK ( const_begin != end ); + } + // testing dereferencing/assignment if ( begin != end ) { From 0316b64019d48b952ccb1cb709234d018ec413f1 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 7 Apr 2014 11:27:46 +0300 Subject: [PATCH 5/7] [point iterator][flatten iterator] replace enable_if mechanism in copy constructor by static asserts; add static assert to assignment operator; make dereference inline; --- .../geometry/iterators/flatten_iterator.hpp | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/include/boost/geometry/iterators/flatten_iterator.hpp b/include/boost/geometry/iterators/flatten_iterator.hpp index ae0145816..1d264f006 100644 --- a/include/boost/geometry/iterators/flatten_iterator.hpp +++ b/include/boost/geometry/iterators/flatten_iterator.hpp @@ -11,7 +11,6 @@ #define BOOST_GEOMETRY_ITERATORS_FLATTEN_ITERATOR_HPP #include -#include #include #include #include @@ -48,8 +47,6 @@ private: OuterIterator m_outer_it, m_outer_end; InnerIterator m_inner_it; - struct enabler {}; - public: typedef OuterIterator outer_iterator_type; typedef InnerIterator inner_iterator_type; @@ -82,24 +79,21 @@ public: OtherValue, OtherAccessInnerBegin, OtherAccessInnerEnd - > const& other, - typename boost::enable_if_c - < - boost::is_convertible - < - OtherOuterIterator, OuterIterator - >::value - && - boost::is_convertible - < - OtherInnerIterator, InnerIterator - >::value, - enabler - >::type = enabler()) + > const& other) : m_outer_it(other.m_outer_it), m_outer_end(other.m_outer_end), m_inner_it(other.m_inner_it) - {} + { + BOOST_STATIC_ASSERT( boost::is_convertible + < + OtherOuterIterator, OuterIterator + >::value + && boost::is_convertible + < + OtherInnerIterator, InnerIterator + >::value ); + + } template < @@ -118,6 +112,15 @@ public: OtherAccessInnerEnd > const& other) { + BOOST_STATIC_ASSERT( boost::is_convertible + < + OtherOuterIterator, OuterIterator + >::value + && boost::is_convertible + < + OtherInnerIterator, InnerIterator + >::value ); + m_outer_it = other.m_outer_it; m_outer_end = other.m_outer_end; m_inner_it = other.m_inner_it; @@ -156,7 +159,7 @@ private: } } - Value& dereference() const + inline Value& dereference() const { BOOST_ASSERT( m_outer_it != m_outer_end ); BOOST_ASSERT( m_inner_it != AccessInnerEnd::apply(*m_outer_it) ); From cb3a103256f7295f50d3b0e68a6ab467244207d1 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 7 Apr 2014 11:30:20 +0300 Subject: [PATCH 6/7] [point iterator] replace enable_if mechanism by static assert; --- .../geometry/iterators/point_iterator.hpp | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/include/boost/geometry/iterators/point_iterator.hpp b/include/boost/geometry/iterators/point_iterator.hpp index 07a70c4e0..a0fc2da4b 100644 --- a/include/boost/geometry/iterators/point_iterator.hpp +++ b/include/boost/geometry/iterators/point_iterator.hpp @@ -10,7 +10,6 @@ #ifndef BOOST_GEOMETRY_ITERATORS_POINT_ITERATOR_HPP #define BOOST_GEOMETRY_ITERATORS_POINT_ITERATOR_HPP -#include #include #include @@ -222,17 +221,6 @@ private: return this; } - template - struct is_convertible - : boost::is_convertible - < - typename dispatch::point_iterator_type::type, - typename dispatch::point_iterator_type::type - > - {}; - - struct enabler {}; - template friend class point_iterator; template friend inline point_iterator points_begin(G&); template friend inline point_iterator points_end(G&); @@ -243,15 +231,16 @@ public: point_iterator() {} template - point_iterator(point_iterator const& other, - typename boost::enable_if - < - is_convertible, - enabler - >::type = enabler()) - + point_iterator(point_iterator const& other) : base(*other.base_ptr()) - {} + { + BOOST_STATIC_ASSERT + ( boost::is_convertible + < + typename dispatch::point_iterator_type::type, + typename dispatch::point_iterator_type::type + >::value ); + } }; From a307bec0906be5eb42b97fb186b5da82aec25e93 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 7 Apr 2014 11:31:42 +0300 Subject: [PATCH 7/7] [point iterator][concatenate iterator] replace enable_if mechanism by static assert; add templated assignment operator; make dereference and increment inline; templatize equal for comparison against other concatenate iterator (needed for interoperability between const/non-const versions); --- .../iterators/concatenate_iterator.hpp | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/include/boost/geometry/iterators/concatenate_iterator.hpp b/include/boost/geometry/iterators/concatenate_iterator.hpp index 3cad9b15a..c0c4f5e08 100644 --- a/include/boost/geometry/iterators/concatenate_iterator.hpp +++ b/include/boost/geometry/iterators/concatenate_iterator.hpp @@ -11,7 +11,6 @@ #define BOOST_GEOMETRY_ITERATORS_CONCATENATE_ITERATOR_HPP #include -#include #include #include #include @@ -35,8 +34,6 @@ private: Iterator1 m_it1, m_end1; Iterator2 m_it2; - struct enabler {}; - public: typedef Iterator1 first_iterator_type; typedef Iterator2 second_iterator_type; @@ -57,17 +54,27 @@ public: template concatenate_iterator - (concatenate_iterator const& other, - typename boost::enable_if_c - < - boost::is_convertible::value - && boost::is_convertible::value, - enabler - >::type = enabler()) + (concatenate_iterator const& other) : m_it1(other.m_it1), m_end1(other.m_end1), m_it2(other.m_it2) - {} + { + BOOST_STATIC_ASSERT + ( boost::is_convertible::value + && boost::is_convertible::value ); + } + template + concatenate_iterator + operator=(concatenate_iterator const& other) + { + BOOST_STATIC_ASSERT + ( boost::is_convertible::value + && boost::is_convertible::value ); + m_it1 = other.m_it1; + m_end1 = other.m_end1; + m_it2 = other.m_it2; + return *this; + } private: friend class boost::iterator_core_access; @@ -75,7 +82,7 @@ private: template friend class concatenate_iterator; - Value& dereference() const + inline Value& dereference() const { if ( m_it1 == m_end1 ) { @@ -84,12 +91,18 @@ private: return *m_it1; } - bool equal(concatenate_iterator const& other) const + template + inline bool equal(concatenate_iterator + < + OtherIt1, + OtherIt2, + OtherValue + > const& other) const { return m_it1 == other.m_it1 && m_it2 == other.m_it2; } - void increment() + inline void increment() { if ( m_it1 == m_end1 ) {