From 9aaffa5f782494ee529ac6a1be6a3ca630148911 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 16 Jun 2014 19:06:19 +0200 Subject: [PATCH 1/9] [geometries] Add support for std::initializer_list --- doc/doxy/Doxyfile | 1 + .../boost/geometry/geometries/linestring.hpp | 12 ++++ .../geometry/geometries/multi_linestring.hpp | 20 ++++++ .../geometry/geometries/multi_polygon.hpp | 21 ++++++ include/boost/geometry/geometries/point.hpp | 2 +- include/boost/geometry/geometries/polygon.hpp | 20 ++++++ include/boost/geometry/geometries/ring.hpp | 12 ++++ test/geometries/Jamfile.v2 | 1 + test/geometries/geometries.cpp | 65 +++++++++++++++++++ 9 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 test/geometries/geometries.cpp diff --git a/doc/doxy/Doxyfile b/doc/doxy/Doxyfile index e3b1ee1be..e9974a3dc 100644 --- a/doc/doxy/Doxyfile +++ b/doc/doxy/Doxyfile @@ -91,6 +91,7 @@ ALIASES = qbk{1}="\xmlonly \1 \endxmlonly" \ param_z="Third coordinate (usually z-coordinate)" \ constructor_default{1}="Default constructor, creating an empty \1" \ constructor_begin_end{1}="Constructor with begin and end, filling the \1" \ + constructor_initializer_list{1}="Constructor with std::initializer_list, filling the \1" \ details_calc{2}="The free function \1 calculates the \2 of a geometry" \ details_calc{1}="The free function \1 calculates the \1 of a geometry" \ details_calc2{2}="The free function \1 calculates the \2 of two geometries" \ diff --git a/include/boost/geometry/geometries/linestring.hpp b/include/boost/geometry/geometries/linestring.hpp index 38bc3d4c4..9a065da84 100644 --- a/include/boost/geometry/geometries/linestring.hpp +++ b/include/boost/geometry/geometries/linestring.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -18,6 +19,7 @@ #include #include +#include #include #include @@ -25,6 +27,9 @@ #include +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#include +#endif namespace boost { namespace geometry { @@ -68,6 +73,13 @@ public : inline linestring(Iterator begin, Iterator end) : base_type(begin, end) {} + +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{linestring} + inline linestring(std::initializer_list l) + : base_type(l.begin(), l.end()) + {} +#endif }; } // namespace model diff --git a/include/boost/geometry/geometries/multi_linestring.hpp b/include/boost/geometry/geometries/multi_linestring.hpp index 2ba8e7196..41d6d7948 100644 --- a/include/boost/geometry/geometries/multi_linestring.hpp +++ b/include/boost/geometry/geometries/multi_linestring.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -18,10 +19,14 @@ #include #include +#include #include #include +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#include +#endif namespace boost { namespace geometry { @@ -50,6 +55,21 @@ template class multi_linestring : public Container > { BOOST_CONCEPT_ASSERT( (concept::Linestring) ); + + typedef Container > base_type; + +public: + /// \constructor_default{multi_linestring} + multi_linestring() + : base_type() + {} + +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{multi_linestring} + inline multi_linestring(std::initializer_list l) + : base_type(l.begin(), l.end()) + {} +#endif }; diff --git a/include/boost/geometry/geometries/multi_polygon.hpp b/include/boost/geometry/geometries/multi_polygon.hpp index 228074cd3..58c89d018 100644 --- a/include/boost/geometry/geometries/multi_polygon.hpp +++ b/include/boost/geometry/geometries/multi_polygon.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -18,10 +19,15 @@ #include #include +#include #include #include +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#include +#endif + namespace boost { namespace geometry { @@ -48,6 +54,21 @@ template class multi_polygon : public Container > { BOOST_CONCEPT_ASSERT( (concept::Polygon) ); + + typedef Container > base_type; + +public: + /// \constructor_default{multi_polygon} + multi_polygon() + : base_type() + {} + +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{multi_polygon} + inline multi_polygon(std::initializer_list l) + : base_type(l.begin(), l.end()) + {} +#endif }; diff --git a/include/boost/geometry/geometries/point.hpp b/include/boost/geometry/geometries/point.hpp index a25340c46..87153a54b 100644 --- a/include/boost/geometry/geometries/point.hpp +++ b/include/boost/geometry/geometries/point.hpp @@ -71,7 +71,7 @@ public: {} /// @brief Constructor to set one, two or three values - explicit inline point(CoordinateType const& v0, CoordinateType const& v1 = 0, CoordinateType const& v2 = 0) + inline point(CoordinateType const& v0, CoordinateType const& v1 = 0, CoordinateType const& v2 = 0) { if (DimensionCount >= 1) m_values[0] = v0; if (DimensionCount >= 2) m_values[1] = v1; diff --git a/include/boost/geometry/geometries/polygon.hpp b/include/boost/geometry/geometries/polygon.hpp index ec8d1ec38..0e8118a60 100644 --- a/include/boost/geometry/geometries/polygon.hpp +++ b/include/boost/geometry/geometries/polygon.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -18,6 +19,7 @@ #include #include +#include #include #include @@ -26,6 +28,10 @@ #include #include +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#include +#endif + namespace boost { namespace geometry { @@ -83,6 +89,20 @@ public: inline ring_type& outer() { return m_outer; } inline inner_container_type & inners() { return m_inners; } + /// \constructor_default{polygon} + inline polygon() + : m_outer() + , m_inners() + {} + +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{polygon} + inline polygon(std::initializer_list l) + : m_outer(l.size() > 0 ? *l.begin() : ring_type()) + , m_inners(l.size() > 0 ? l.begin() + 1 : l.begin(), l.end()) + {} +#endif + /// Utility method, clears outer and inner rings inline void clear() { diff --git a/include/boost/geometry/geometries/ring.hpp b/include/boost/geometry/geometries/ring.hpp index 998619785..49b6292bd 100644 --- a/include/boost/geometry/geometries/ring.hpp +++ b/include/boost/geometry/geometries/ring.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -18,6 +19,7 @@ #include #include +#include #include #include @@ -26,6 +28,9 @@ #include +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#include +#endif namespace boost { namespace geometry { @@ -72,6 +77,13 @@ public : inline ring(Iterator begin, Iterator end) : base_type(begin, end) {} + +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{ring} + inline ring(std::initializer_list l) + : base_type(l.begin(), l.end()) + {} +#endif }; } // namespace model diff --git a/test/geometries/Jamfile.v2 b/test/geometries/Jamfile.v2 index 763b9b6f0..c1a09970e 100644 --- a/test/geometries/Jamfile.v2 +++ b/test/geometries/Jamfile.v2 @@ -24,5 +24,6 @@ test-suite boost-geometry-geometries # custom_linestring_test_fail_clear #] [ run custom_linestring.cpp ] + [ run geometries.cpp ] [ run segment.cpp ] ; diff --git a/test/geometries/geometries.cpp b/test/geometries/geometries.cpp new file mode 100644 index 000000000..7dd1a462c --- /dev/null +++ b/test/geometries/geometries.cpp @@ -0,0 +1,65 @@ +// Boost.Geometry +// Unit Test + +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +#include + +#include +#include + +#include +#include +#include + +template +void test_all_2d() +{ +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + + typedef bg::model::linestring

ls; + typedef bg::model::multi_linestring mls; + typedef bg::model::ring

ring; + typedef bg::model::polygon

poly; + typedef bg::model::multi_polygon mpoly; + + ls ls1 = {{0, 0}, {1, 0}, {2, 0}}; + BOOST_CHECK(bg::num_geometries(ls1) == 1); + BOOST_CHECK(bg::num_points(ls1) == 3); + + mls mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}}}; + BOOST_CHECK(bg::num_geometries(mls1) == 2); + BOOST_CHECK(bg::num_points(mls1) == 5); + + ring r1 = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; + BOOST_CHECK(bg::num_geometries(r1) == 1); + BOOST_CHECK(bg::num_points(r1) == 5); + + poly p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; + BOOST_CHECK(bg::num_geometries(p1) == 1); + BOOST_CHECK(bg::num_points(p1) == 10); + poly p2 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; + BOOST_CHECK(bg::num_geometries(p2) == 1); + BOOST_CHECK(bg::num_points(p2) == 5); + + mpoly mp1 = {{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; + BOOST_CHECK(bg::num_geometries(mp1) == 2); + BOOST_CHECK(bg::num_points(mp1) == 10); + +#endif +} + +int test_main(int, char* []) +{ + test_all_2d< bg::model::point >(); + test_all_2d< bg::model::d2::point_xy >(); + + return 0; +} + From 81bcdc34edaea7de0cc082d9c30247cabb746484 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 16 Jun 2014 23:54:16 +0200 Subject: [PATCH 2/9] [geometries] Define assignment operators taking initializer lists. Add constructor taking initializer list for multi_point. --- doc/doxy/Doxyfile | 3 ++- .../boost/geometry/geometries/linestring.hpp | 7 +++++++ .../geometry/geometries/multi_linestring.hpp | 7 +++++++ .../boost/geometry/geometries/multi_point.hpp | 18 ++++++++++++++++++ .../geometry/geometries/multi_polygon.hpp | 7 +++++++ include/boost/geometry/geometries/polygon.hpp | 16 ++++++++++++++++ include/boost/geometry/geometries/ring.hpp | 7 +++++++ test/geometries/geometries.cpp | 17 +++++++++++++++++ 8 files changed, 81 insertions(+), 1 deletion(-) diff --git a/doc/doxy/Doxyfile b/doc/doxy/Doxyfile index e9974a3dc..406b4c1a2 100644 --- a/doc/doxy/Doxyfile +++ b/doc/doxy/Doxyfile @@ -91,7 +91,8 @@ ALIASES = qbk{1}="\xmlonly \1 \endxmlonly" \ param_z="Third coordinate (usually z-coordinate)" \ constructor_default{1}="Default constructor, creating an empty \1" \ constructor_begin_end{1}="Constructor with begin and end, filling the \1" \ - constructor_initializer_list{1}="Constructor with std::initializer_list, filling the \1" \ + constructor_initializer_list{1}="Constructor taking std::initializer_list, filling the \1" \ + assignment_initializer_list{1}="Assignment operator taking std::initializer_list, assigning values to the \1" \ details_calc{2}="The free function \1 calculates the \2 of a geometry" \ details_calc{1}="The free function \1 calculates the \1 of a geometry" \ details_calc2{2}="The free function \1 calculates the \2 of two geometries" \ diff --git a/include/boost/geometry/geometries/linestring.hpp b/include/boost/geometry/geometries/linestring.hpp index 9a065da84..cf6519514 100644 --- a/include/boost/geometry/geometries/linestring.hpp +++ b/include/boost/geometry/geometries/linestring.hpp @@ -79,6 +79,13 @@ public : inline linestring(std::initializer_list l) : base_type(l.begin(), l.end()) {} + + /// \assignment_initializer_list{linestring} + inline linestring & operator=(std::initializer_list l) + { + base_type::assign(l.begin(), l.end()); + return *this; + } #endif }; diff --git a/include/boost/geometry/geometries/multi_linestring.hpp b/include/boost/geometry/geometries/multi_linestring.hpp index 41d6d7948..250c8e5d1 100644 --- a/include/boost/geometry/geometries/multi_linestring.hpp +++ b/include/boost/geometry/geometries/multi_linestring.hpp @@ -69,6 +69,13 @@ public: inline multi_linestring(std::initializer_list l) : base_type(l.begin(), l.end()) {} + + /// \assignment_initializer_list{multi_linestring} + inline multi_linestring & operator=(std::initializer_list l) + { + base_type::assign(l.begin(), l.end()); + return *this; + } #endif }; diff --git a/include/boost/geometry/geometries/multi_point.hpp b/include/boost/geometry/geometries/multi_point.hpp index d0a782a1d..e8a0d7d75 100644 --- a/include/boost/geometry/geometries/multi_point.hpp +++ b/include/boost/geometry/geometries/multi_point.hpp @@ -18,10 +18,14 @@ #include #include +#include #include #include +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#include +#endif namespace boost { namespace geometry { @@ -66,6 +70,20 @@ public : inline multi_point(Iterator begin, Iterator end) : base_type(begin, end) {} + +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{multi_point} + inline multi_point(std::initializer_list l) + : base_type(l.begin(), l.end()) + {} + + /// \assignment_initializer_list{multi_point} + inline multi_point & operator=(std::initializer_list l) + { + base_type::assign(l.begin(), l.end()); + return *this; + } +#endif }; } // namespace model diff --git a/include/boost/geometry/geometries/multi_polygon.hpp b/include/boost/geometry/geometries/multi_polygon.hpp index 58c89d018..0c8548c30 100644 --- a/include/boost/geometry/geometries/multi_polygon.hpp +++ b/include/boost/geometry/geometries/multi_polygon.hpp @@ -68,6 +68,13 @@ public: inline multi_polygon(std::initializer_list l) : base_type(l.begin(), l.end()) {} + + /// \assignment_initializer_list{multi_polygon} + inline multi_polygon & operator=(std::initializer_list l) + { + base_type::assign(l.begin(), l.end()); + return *this; + } #endif }; diff --git a/include/boost/geometry/geometries/polygon.hpp b/include/boost/geometry/geometries/polygon.hpp index 0e8118a60..6d5b6209a 100644 --- a/include/boost/geometry/geometries/polygon.hpp +++ b/include/boost/geometry/geometries/polygon.hpp @@ -101,6 +101,22 @@ public: : m_outer(l.size() > 0 ? *l.begin() : ring_type()) , m_inners(l.size() > 0 ? l.begin() + 1 : l.begin(), l.end()) {} + + /// \assignment_initializer_list{polygon} + inline polygon & operator=(std::initializer_list l) + { + if ( l.size() > 0 ) + { + m_outer = *l.begin(); + m_inners.assign(l.begin() + 1, l.end()); + } + else + { + m_outer.clear(); + m_inners.clear(); + } + return *this; + } #endif /// Utility method, clears outer and inner rings diff --git a/include/boost/geometry/geometries/ring.hpp b/include/boost/geometry/geometries/ring.hpp index 49b6292bd..bd51ac774 100644 --- a/include/boost/geometry/geometries/ring.hpp +++ b/include/boost/geometry/geometries/ring.hpp @@ -83,6 +83,13 @@ public : inline ring(std::initializer_list l) : base_type(l.begin(), l.end()) {} + + /// \assignment_initializer_list{ring} + inline ring & operator=(std::initializer_list l) + { + base_type::assign(l.begin(), l.end()); + return *this; + } #endif }; diff --git a/test/geometries/geometries.cpp b/test/geometries/geometries.cpp index 7dd1a462c..adf633758 100644 --- a/test/geometries/geometries.cpp +++ b/test/geometries/geometries.cpp @@ -23,23 +23,36 @@ void test_all_2d() { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + typedef bg::model::multi_point

mpt; typedef bg::model::linestring

ls; typedef bg::model::multi_linestring mls; typedef bg::model::ring

ring; typedef bg::model::polygon

poly; typedef bg::model::multi_polygon mpoly; + mpt mpt1 = {{0, 0}, {1, 0}, {2, 0}}; + BOOST_CHECK(bg::num_geometries(mpt1) == 3); + BOOST_CHECK(bg::num_points(mpt1) == 3); + mpt1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; + BOOST_CHECK(bg::num_points(mpt1) == 4); + ls ls1 = {{0, 0}, {1, 0}, {2, 0}}; BOOST_CHECK(bg::num_geometries(ls1) == 1); BOOST_CHECK(bg::num_points(ls1) == 3); + ls1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; + BOOST_CHECK(bg::num_points(ls1) == 4); mls mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}}}; BOOST_CHECK(bg::num_geometries(mls1) == 2); BOOST_CHECK(bg::num_points(mls1) == 5); + mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}, {5, 0}}}; + BOOST_CHECK(bg::num_points(mls1) == 6); ring r1 = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; BOOST_CHECK(bg::num_geometries(r1) == 1); BOOST_CHECK(bg::num_points(r1) == 5); + r1 = {{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}; + BOOST_CHECK(bg::num_points(r1) == 6); poly p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; BOOST_CHECK(bg::num_geometries(p1) == 1); @@ -47,10 +60,14 @@ void test_all_2d() poly p2 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; BOOST_CHECK(bg::num_geometries(p2) == 1); BOOST_CHECK(bg::num_points(p2) == 5); + p2 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}}; + BOOST_CHECK(bg::num_points(p2) == 6); mpoly mp1 = {{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; BOOST_CHECK(bg::num_geometries(mp1) == 2); BOOST_CHECK(bg::num_points(mp1) == 10); + mp1 = {{{{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; + BOOST_CHECK(bg::num_points(mp1) == 11); #endif } From a9e4957800edeb9d57e89f7485cc8f09bccdf479 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Tue, 17 Jun 2014 13:52:33 +0200 Subject: [PATCH 3/9] [geometries] Added tests, also for Boost.Assign --- .../boost/geometry/geometries/multi_point.hpp | 1 + include/boost/geometry/geometries/point.hpp | 1 + include/boost/geometry/geometries/polygon.hpp | 15 ++++ test/geometries/Jamfile.v2 | 1 + test/geometries/geometries.cpp | 78 ++++++++++++++++++- 5 files changed, 95 insertions(+), 1 deletion(-) diff --git a/include/boost/geometry/geometries/multi_point.hpp b/include/boost/geometry/geometries/multi_point.hpp index e8a0d7d75..a101a8d5f 100644 --- a/include/boost/geometry/geometries/multi_point.hpp +++ b/include/boost/geometry/geometries/multi_point.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. diff --git a/include/boost/geometry/geometries/point.hpp b/include/boost/geometry/geometries/point.hpp index 87153a54b..b6c61b4bc 100644 --- a/include/boost/geometry/geometries/point.hpp +++ b/include/boost/geometry/geometries/point.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. diff --git a/include/boost/geometry/geometries/polygon.hpp b/include/boost/geometry/geometries/polygon.hpp index 6d5b6209a..fbad47c0c 100644 --- a/include/boost/geometry/geometries/polygon.hpp +++ b/include/boost/geometry/geometries/polygon.hpp @@ -117,6 +117,21 @@ public: } return *this; } + + // ambiguous + /*/// \constructor_initializer_list{polygon} + inline polygon(std::initializer_list l) + : m_outer(l.begin(), l.end()) + , m_inners() + {} + + /// \assignment_initializer_list{polygon} + inline polygon & operator=(std::initializer_list l) + { + m_outer.assign(l.begin(), l.end()); + m_inners.clear(); + return *this; + }*/ #endif /// Utility method, clears outer and inner rings diff --git a/test/geometries/Jamfile.v2 b/test/geometries/Jamfile.v2 index c1a09970e..9999c7280 100644 --- a/test/geometries/Jamfile.v2 +++ b/test/geometries/Jamfile.v2 @@ -3,6 +3,7 @@ # Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. # Copyright (c) 2008-2012 Bruno Lalande, Paris, France. # Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +# Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. # Use, modification and distribution is subject to the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/test/geometries/geometries.cpp b/test/geometries/geometries.cpp index adf633758..655a79286 100644 --- a/test/geometries/geometries.cpp +++ b/test/geometries/geometries.cpp @@ -9,6 +9,7 @@ #include +#include #include #include @@ -19,7 +20,52 @@ #include template -void test_all_2d() +void test_default() +{ + typedef bg::model::multi_point

mpt; + typedef bg::model::linestring

ls; + typedef bg::model::multi_linestring mls; + typedef bg::model::ring

ring; + typedef bg::model::polygon

poly; + typedef bg::model::multi_polygon mpoly; + + // multi_point() + mpt mptd; + BOOST_CHECK(bg::num_points(mptd) == 0); + // linestring() + ls lsd; + BOOST_CHECK(bg::num_points(lsd) == 0); + // multi_linestring() + mls mlsd; + BOOST_CHECK(bg::num_points(mlsd) == 0); + // ring() + ring rd; + BOOST_CHECK(bg::num_points(rd) == 0); + // polygon() + poly pd; + BOOST_CHECK(bg::num_points(pd) == 0); + // multi_polygon() + mpoly mpd; + BOOST_CHECK(bg::num_points(mpd) == 0); +} + +template +void test_boost_assign_2d() +{ + typedef bg::model::multi_point

mpt; + typedef bg::model::linestring

ls; + + // using Boost.Assign + mpt mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); + BOOST_CHECK(bg::num_points(mpt2) == 2); + + // using Boost.Assign + mpt ls2 = boost::assign::list_of(P(0, 0))(P(1, 0)); + BOOST_CHECK(bg::num_points(ls2) == 2); +} + +template +void test_initializer_list_2d() { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) @@ -30,48 +76,78 @@ void test_all_2d() typedef bg::model::polygon

poly; typedef bg::model::multi_polygon mpoly; + // multi_point(initializer_list) mpt mpt1 = {{0, 0}, {1, 0}, {2, 0}}; BOOST_CHECK(bg::num_geometries(mpt1) == 3); BOOST_CHECK(bg::num_points(mpt1) == 3); + // multi_point::operator=(initializer_list) mpt1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; BOOST_CHECK(bg::num_points(mpt1) == 4); + // linestring(initializer_list) ls ls1 = {{0, 0}, {1, 0}, {2, 0}}; BOOST_CHECK(bg::num_geometries(ls1) == 1); BOOST_CHECK(bg::num_points(ls1) == 3); + // linestring::operator=(initializer_list) ls1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; BOOST_CHECK(bg::num_points(ls1) == 4); + // multi_linestring(initializer_list) mls mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}}}; BOOST_CHECK(bg::num_geometries(mls1) == 2); BOOST_CHECK(bg::num_points(mls1) == 5); + // multi_linestring::operator=(initializer_list) mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}, {5, 0}}}; BOOST_CHECK(bg::num_points(mls1) == 6); + // ring(initializer_list) ring r1 = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; BOOST_CHECK(bg::num_geometries(r1) == 1); BOOST_CHECK(bg::num_points(r1) == 5); + // ring::operator=(initializer_list) r1 = {{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}; BOOST_CHECK(bg::num_points(r1) == 6); + // polygon(initializer_list) poly p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; BOOST_CHECK(bg::num_geometries(p1) == 1); BOOST_CHECK(bg::num_points(p1) == 10); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1); + // polygon::operator=(initializer_list) + p1 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; + BOOST_CHECK(bg::num_points(p1) == 11); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1); + p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; + BOOST_CHECK(bg::num_points(p1) == 5); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0); + // polygon(initializer_list) poly p2 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; BOOST_CHECK(bg::num_geometries(p2) == 1); BOOST_CHECK(bg::num_points(p2) == 5); + BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0); + // polygon::operator=(initializer_list) p2 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}}; BOOST_CHECK(bg::num_points(p2) == 6); + // multi_polygon(initializer_list) mpoly mp1 = {{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; BOOST_CHECK(bg::num_geometries(mp1) == 2); BOOST_CHECK(bg::num_points(mp1) == 10); + // multi_polygon::operator=(initializer_list) mp1 = {{{{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; BOOST_CHECK(bg::num_points(mp1) == 11); #endif } +template +void test_all_2d() +{ + test_default

(); + test_boost_assign_2d

(); + test_initializer_list_2d

(); +} + int test_main(int, char* []) { test_all_2d< bg::model::point >(); From 4c944a60bb4a7579d4f55fe2fea3117b97bee439 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Tue, 30 Dec 2014 02:36:31 +0100 Subject: [PATCH 4/9] [geometries] Add MSVC workarounds for assignments taking std::initializer_list. Don't define assignment operator taking std::initializer_list on MSVC. On this compiler, when an initializer_list is assigned, first an object is created using ctor taking initializer_list and then it's moved. --- .../boost/geometry/geometries/linestring.hpp | 5 +++++ .../geometry/geometries/multi_linestring.hpp | 5 +++++ .../boost/geometry/geometries/multi_point.hpp | 5 +++++ .../boost/geometry/geometries/multi_polygon.hpp | 5 +++++ include/boost/geometry/geometries/polygon.hpp | 17 +++-------------- include/boost/geometry/geometries/ring.hpp | 5 +++++ 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/boost/geometry/geometries/linestring.hpp b/include/boost/geometry/geometries/linestring.hpp index cf6519514..8f39ec3d8 100644 --- a/include/boost/geometry/geometries/linestring.hpp +++ b/include/boost/geometry/geometries/linestring.hpp @@ -75,11 +75,14 @@ public : {} #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{linestring} inline linestring(std::initializer_list l) : base_type(l.begin(), l.end()) {} +// Without this workaround in MSVC the assignment operator is ambiguous +#ifndef BOOST_MSVC /// \assignment_initializer_list{linestring} inline linestring & operator=(std::initializer_list l) { @@ -87,6 +90,8 @@ public : return *this; } #endif + +#endif }; } // namespace model diff --git a/include/boost/geometry/geometries/multi_linestring.hpp b/include/boost/geometry/geometries/multi_linestring.hpp index 250c8e5d1..6eee45c8d 100644 --- a/include/boost/geometry/geometries/multi_linestring.hpp +++ b/include/boost/geometry/geometries/multi_linestring.hpp @@ -65,11 +65,14 @@ public: {} #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{multi_linestring} inline multi_linestring(std::initializer_list l) : base_type(l.begin(), l.end()) {} +// Without this workaround in MSVC the assignment operator is ambiguous +#ifndef BOOST_MSVC /// \assignment_initializer_list{multi_linestring} inline multi_linestring & operator=(std::initializer_list l) { @@ -77,6 +80,8 @@ public: return *this; } #endif + +#endif }; diff --git a/include/boost/geometry/geometries/multi_point.hpp b/include/boost/geometry/geometries/multi_point.hpp index a101a8d5f..095aab93d 100644 --- a/include/boost/geometry/geometries/multi_point.hpp +++ b/include/boost/geometry/geometries/multi_point.hpp @@ -73,11 +73,14 @@ public : {} #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{multi_point} inline multi_point(std::initializer_list l) : base_type(l.begin(), l.end()) {} +// Without this workaround in MSVC the assignment operator is ambiguous +#ifndef BOOST_MSVC /// \assignment_initializer_list{multi_point} inline multi_point & operator=(std::initializer_list l) { @@ -85,6 +88,8 @@ public : return *this; } #endif + +#endif }; } // namespace model diff --git a/include/boost/geometry/geometries/multi_polygon.hpp b/include/boost/geometry/geometries/multi_polygon.hpp index 0c8548c30..3ba295406 100644 --- a/include/boost/geometry/geometries/multi_polygon.hpp +++ b/include/boost/geometry/geometries/multi_polygon.hpp @@ -64,11 +64,14 @@ public: {} #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{multi_polygon} inline multi_polygon(std::initializer_list l) : base_type(l.begin(), l.end()) {} +// Without this workaround in MSVC the assignment operator is ambiguous +#ifndef BOOST_MSVC /// \assignment_initializer_list{multi_polygon} inline multi_polygon & operator=(std::initializer_list l) { @@ -76,6 +79,8 @@ public: return *this; } #endif + +#endif }; diff --git a/include/boost/geometry/geometries/polygon.hpp b/include/boost/geometry/geometries/polygon.hpp index fbad47c0c..069716166 100644 --- a/include/boost/geometry/geometries/polygon.hpp +++ b/include/boost/geometry/geometries/polygon.hpp @@ -102,6 +102,8 @@ public: , m_inners(l.size() > 0 ? l.begin() + 1 : l.begin(), l.end()) {} +// Without this workaround in MSVC the assignment operator is ambiguous +#ifndef BOOST_MSVC /// \assignment_initializer_list{polygon} inline polygon & operator=(std::initializer_list l) { @@ -117,21 +119,8 @@ public: } return *this; } +#endif - // ambiguous - /*/// \constructor_initializer_list{polygon} - inline polygon(std::initializer_list l) - : m_outer(l.begin(), l.end()) - , m_inners() - {} - - /// \assignment_initializer_list{polygon} - inline polygon & operator=(std::initializer_list l) - { - m_outer.assign(l.begin(), l.end()); - m_inners.clear(); - return *this; - }*/ #endif /// Utility method, clears outer and inner rings diff --git a/include/boost/geometry/geometries/ring.hpp b/include/boost/geometry/geometries/ring.hpp index bd51ac774..ca23676bd 100644 --- a/include/boost/geometry/geometries/ring.hpp +++ b/include/boost/geometry/geometries/ring.hpp @@ -79,11 +79,14 @@ public : {} #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + /// \constructor_initializer_list{ring} inline ring(std::initializer_list l) : base_type(l.begin(), l.end()) {} +// Without this workaround in MSVC the assignment operator is ambiguous +#ifndef BOOST_MSVC /// \assignment_initializer_list{ring} inline ring & operator=(std::initializer_list l) { @@ -91,6 +94,8 @@ public : return *this; } #endif + +#endif }; } // namespace model From ac5b9ef9acb6677b431f3efc7d6b9a2b47ec519e Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Tue, 30 Dec 2014 02:46:29 +0100 Subject: [PATCH 5/9] [test][geometry] Add Boost.Assign list_of test for linestring and ring. --- test/geometries/geometries.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/geometries/geometries.cpp b/test/geometries/geometries.cpp index 655a79286..3bd787177 100644 --- a/test/geometries/geometries.cpp +++ b/test/geometries/geometries.cpp @@ -54,14 +54,19 @@ void test_boost_assign_2d() { typedef bg::model::multi_point

mpt; typedef bg::model::linestring

ls; + typedef bg::model::ring

ring; // using Boost.Assign mpt mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); BOOST_CHECK(bg::num_points(mpt2) == 2); // using Boost.Assign - mpt ls2 = boost::assign::list_of(P(0, 0))(P(1, 0)); - BOOST_CHECK(bg::num_points(ls2) == 2); + ls ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1)); + BOOST_CHECK(bg::num_points(ls2) == 3); + + // using Boost.Assign + ring r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0)); + BOOST_CHECK(bg::num_points(r2) == 5); } template From f6f59869e451a8a34a6aeedcaf58a1a1067e97d8 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Tue, 30 Dec 2014 13:56:04 +0100 Subject: [PATCH 6/9] [test][geometries] Test Boost.Assign and initializer lists for points being std::pair or boost::tuple. --- test/geometries/geometries.cpp | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/geometries/geometries.cpp b/test/geometries/geometries.cpp index 3bd787177..d4ae9b718 100644 --- a/test/geometries/geometries.cpp +++ b/test/geometries/geometries.cpp @@ -14,11 +14,17 @@ #include #include +#include +#include #include #include #include +typedef std::pair pt_pair_t; +BOOST_GEOMETRY_REGISTER_POINT_2D(pt_pair_t, float, bg::cs::cartesian, first, second) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + template void test_default() { @@ -59,14 +65,50 @@ void test_boost_assign_2d() // using Boost.Assign mpt mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); BOOST_CHECK(bg::num_points(mpt2) == 2); + mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); + BOOST_CHECK(bg::num_points(mpt2) == 2); // using Boost.Assign ls ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1)); BOOST_CHECK(bg::num_points(ls2) == 3); + ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1)); + BOOST_CHECK(bg::num_points(ls2) == 3); // using Boost.Assign ring r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0)); BOOST_CHECK(bg::num_points(r2) == 5); + r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0)); + BOOST_CHECK(bg::num_points(r2) == 5); +} + +void test_boost_assign_pair_2d() +{ + typedef std::pair pt; + + test_boost_assign_2d(); + + typedef bg::model::multi_point mpt; + + // using Boost.Assign + mpt mpt2 = boost::assign::pair_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); + mpt2 = boost::assign::pair_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); +} + +void test_boost_assign_tuple_2d() +{ + typedef boost::tuple pt; + + test_boost_assign_2d(); + + typedef bg::model::multi_point mpt; + + // using Boost.Assign + mpt mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); + mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0); + BOOST_CHECK(bg::num_points(mpt2) == 2); } template @@ -158,6 +200,9 @@ int test_main(int, char* []) test_all_2d< bg::model::point >(); test_all_2d< bg::model::d2::point_xy >(); + test_boost_assign_pair_2d(); + test_boost_assign_tuple_2d(); + return 0; } From 1ab3905687802b747365dfdea659770144943311 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sat, 3 Jan 2015 00:15:41 +0100 Subject: [PATCH 7/9] [geometries] Comment out assignment operators taking initializer_list<>. In order to support Boost.Assign. --- .../boost/geometry/geometries/linestring.hpp | 21 +++++----- .../geometry/geometries/multi_linestring.hpp | 21 +++++----- .../boost/geometry/geometries/multi_point.hpp | 21 +++++----- .../geometry/geometries/multi_polygon.hpp | 21 +++++----- include/boost/geometry/geometries/polygon.hpp | 39 ++++++++++--------- include/boost/geometry/geometries/ring.hpp | 21 +++++----- 6 files changed, 81 insertions(+), 63 deletions(-) diff --git a/include/boost/geometry/geometries/linestring.hpp b/include/boost/geometry/geometries/linestring.hpp index 8f39ec3d8..73e2aea75 100644 --- a/include/boost/geometry/geometries/linestring.hpp +++ b/include/boost/geometry/geometries/linestring.hpp @@ -81,15 +81,18 @@ public : : base_type(l.begin(), l.end()) {} -// Without this workaround in MSVC the assignment operator is ambiguous -#ifndef BOOST_MSVC - /// \assignment_initializer_list{linestring} - inline linestring & operator=(std::initializer_list l) - { - base_type::assign(l.begin(), l.end()); - return *this; - } -#endif +// Commented out for now in order to support Boost.Assign +// Without this assignment operator first the object should be created +// from initializer list, then it shoudl be moved. +//// Without this workaround in MSVC the assignment operator is ambiguous +//#ifndef BOOST_MSVC +// /// \assignment_initializer_list{linestring} +// inline linestring & operator=(std::initializer_list l) +// { +// base_type::assign(l.begin(), l.end()); +// return *this; +// } +//#endif #endif }; diff --git a/include/boost/geometry/geometries/multi_linestring.hpp b/include/boost/geometry/geometries/multi_linestring.hpp index 6eee45c8d..3ba88f182 100644 --- a/include/boost/geometry/geometries/multi_linestring.hpp +++ b/include/boost/geometry/geometries/multi_linestring.hpp @@ -71,15 +71,18 @@ public: : base_type(l.begin(), l.end()) {} -// Without this workaround in MSVC the assignment operator is ambiguous -#ifndef BOOST_MSVC - /// \assignment_initializer_list{multi_linestring} - inline multi_linestring & operator=(std::initializer_list l) - { - base_type::assign(l.begin(), l.end()); - return *this; - } -#endif +// Commented out for now in order to support Boost.Assign +// Without this assignment operator first the object should be created +// from initializer list, then it shoudl be moved. +//// Without this workaround in MSVC the assignment operator is ambiguous +//#ifndef BOOST_MSVC +// /// \assignment_initializer_list{multi_linestring} +// inline multi_linestring & operator=(std::initializer_list l) +// { +// base_type::assign(l.begin(), l.end()); +// return *this; +// } +//#endif #endif }; diff --git a/include/boost/geometry/geometries/multi_point.hpp b/include/boost/geometry/geometries/multi_point.hpp index 095aab93d..839c1c304 100644 --- a/include/boost/geometry/geometries/multi_point.hpp +++ b/include/boost/geometry/geometries/multi_point.hpp @@ -79,15 +79,18 @@ public : : base_type(l.begin(), l.end()) {} -// Without this workaround in MSVC the assignment operator is ambiguous -#ifndef BOOST_MSVC - /// \assignment_initializer_list{multi_point} - inline multi_point & operator=(std::initializer_list l) - { - base_type::assign(l.begin(), l.end()); - return *this; - } -#endif +// Commented out for now in order to support Boost.Assign +// Without this assignment operator first the object should be created +// from initializer list, then it shoudl be moved. +//// Without this workaround in MSVC the assignment operator is ambiguous +//#ifndef BOOST_MSVC +// /// \assignment_initializer_list{multi_point} +// inline multi_point & operator=(std::initializer_list l) +// { +// base_type::assign(l.begin(), l.end()); +// return *this; +// } +//#endif #endif }; diff --git a/include/boost/geometry/geometries/multi_polygon.hpp b/include/boost/geometry/geometries/multi_polygon.hpp index 3ba295406..0d4d64e2b 100644 --- a/include/boost/geometry/geometries/multi_polygon.hpp +++ b/include/boost/geometry/geometries/multi_polygon.hpp @@ -70,15 +70,18 @@ public: : base_type(l.begin(), l.end()) {} -// Without this workaround in MSVC the assignment operator is ambiguous -#ifndef BOOST_MSVC - /// \assignment_initializer_list{multi_polygon} - inline multi_polygon & operator=(std::initializer_list l) - { - base_type::assign(l.begin(), l.end()); - return *this; - } -#endif +// Commented out for now in order to support Boost.Assign +// Without this assignment operator first the object should be created +// from initializer list, then it shoudl be moved. +//// Without this workaround in MSVC the assignment operator is ambiguous +//#ifndef BOOST_MSVC +// /// \assignment_initializer_list{multi_polygon} +// inline multi_polygon & operator=(std::initializer_list l) +// { +// base_type::assign(l.begin(), l.end()); +// return *this; +// } +//#endif #endif }; diff --git a/include/boost/geometry/geometries/polygon.hpp b/include/boost/geometry/geometries/polygon.hpp index 069716166..dfa1866d5 100644 --- a/include/boost/geometry/geometries/polygon.hpp +++ b/include/boost/geometry/geometries/polygon.hpp @@ -102,24 +102,27 @@ public: , m_inners(l.size() > 0 ? l.begin() + 1 : l.begin(), l.end()) {} -// Without this workaround in MSVC the assignment operator is ambiguous -#ifndef BOOST_MSVC - /// \assignment_initializer_list{polygon} - inline polygon & operator=(std::initializer_list l) - { - if ( l.size() > 0 ) - { - m_outer = *l.begin(); - m_inners.assign(l.begin() + 1, l.end()); - } - else - { - m_outer.clear(); - m_inners.clear(); - } - return *this; - } -#endif +// Commented out for now in order to support Boost.Assign +// Without this assignment operator first the object should be created +// from initializer list, then it shoudl be moved. +//// Without this workaround in MSVC the assignment operator is ambiguous +//#ifndef BOOST_MSVC +// /// \assignment_initializer_list{polygon} +// inline polygon & operator=(std::initializer_list l) +// { +// if ( l.size() > 0 ) +// { +// m_outer = *l.begin(); +// m_inners.assign(l.begin() + 1, l.end()); +// } +// else +// { +// m_outer.clear(); +// m_inners.clear(); +// } +// return *this; +// } +//#endif #endif diff --git a/include/boost/geometry/geometries/ring.hpp b/include/boost/geometry/geometries/ring.hpp index ca23676bd..df875569e 100644 --- a/include/boost/geometry/geometries/ring.hpp +++ b/include/boost/geometry/geometries/ring.hpp @@ -85,15 +85,18 @@ public : : base_type(l.begin(), l.end()) {} -// Without this workaround in MSVC the assignment operator is ambiguous -#ifndef BOOST_MSVC - /// \assignment_initializer_list{ring} - inline ring & operator=(std::initializer_list l) - { - base_type::assign(l.begin(), l.end()); - return *this; - } -#endif +// Commented out for now in order to support Boost.Assign +// Without this assignment operator first the object should be created +// from initializer list, then it shoudl be moved. +//// Without this workaround in MSVC the assignment operator is ambiguous +//#ifndef BOOST_MSVC +// /// \assignment_initializer_list{ring} +// inline ring & operator=(std::initializer_list l) +// { +// base_type::assign(l.begin(), l.end()); +// return *this; +// } +//#endif #endif }; From e91e02ed0a8ebdf2de6594a0354d7d1a196145a6 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sat, 3 Jan 2015 00:19:30 +0100 Subject: [PATCH 8/9] [test][geometries] Add non-geometry test for initializer_list<> and Boost.Assign. --- test/geometries/geometries.cpp | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/geometries/geometries.cpp b/test/geometries/geometries.cpp index d4ae9b718..8510df1da 100644 --- a/test/geometries/geometries.cpp +++ b/test/geometries/geometries.cpp @@ -195,6 +195,49 @@ void test_all_2d() test_initializer_list_2d

(); } +template +struct test_point +{ + test_point(T = T(), T = T()) {} +}; + +template +struct test_range +{ + test_range() {} + template + test_range(It, It) {} +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + test_range(std::initializer_list) {} + //test_range & operator=(std::initializer_list) { return *this; } +#endif +}; + +void test_sanity_check() +{ + typedef test_point P; + typedef test_range

R; + typedef std::vector

V; + +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + R r = {{1, 1},{2, 2},{3, 3}}; + r = {{1, 1},{2, 2},{3, 3}}; + + V v = {{1, 1},{2, 2},{3, 3}}; + v = {{1, 1},{2, 2},{3, 3}}; + } +#endif + { + R r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + + V v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + //v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); + v.empty(); + } +} + int test_main(int, char* []) { test_all_2d< bg::model::point >(); @@ -203,6 +246,8 @@ int test_main(int, char* []) test_boost_assign_pair_2d(); test_boost_assign_tuple_2d(); + test_sanity_check(); + return 0; } From 62375c09aaca649660ee20e5161aa6358f3cfa7f Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sat, 10 Jan 2015 01:01:45 +0100 Subject: [PATCH 9/9] [geometries] Shield initializer list support with #ifdef. In order to test it on various compilers using Boost regression testing suite before enabling the support by default. --- include/boost/geometry/geometries/linestring.hpp | 8 ++++++-- include/boost/geometry/geometries/multi_linestring.hpp | 7 ++++++- include/boost/geometry/geometries/multi_point.hpp | 6 +++++- include/boost/geometry/geometries/multi_polygon.hpp | 7 ++++++- include/boost/geometry/geometries/polygon.hpp | 7 ++++++- include/boost/geometry/geometries/ring.hpp | 6 +++++- test/geometries/Jamfile.v2 | 2 +- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/include/boost/geometry/geometries/linestring.hpp b/include/boost/geometry/geometries/linestring.hpp index 73e2aea75..68dc87a3c 100644 --- a/include/boost/geometry/geometries/linestring.hpp +++ b/include/boost/geometry/geometries/linestring.hpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -27,9 +26,12 @@ #include +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST +#include #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST #include #endif +#endif namespace boost { namespace geometry { @@ -74,6 +76,7 @@ public : : base_type(begin, end) {} +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST /// \constructor_initializer_list{linestring} @@ -83,7 +86,7 @@ public : // Commented out for now in order to support Boost.Assign // Without this assignment operator first the object should be created -// from initializer list, then it shoudl be moved. +// from initializer list, then it should be moved. //// Without this workaround in MSVC the assignment operator is ambiguous //#ifndef BOOST_MSVC // /// \assignment_initializer_list{linestring} @@ -94,6 +97,7 @@ public : // } //#endif +#endif #endif }; diff --git a/include/boost/geometry/geometries/multi_linestring.hpp b/include/boost/geometry/geometries/multi_linestring.hpp index 3ba88f182..195a58139 100644 --- a/include/boost/geometry/geometries/multi_linestring.hpp +++ b/include/boost/geometry/geometries/multi_linestring.hpp @@ -19,14 +19,16 @@ #include #include -#include #include #include +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST +#include #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST #include #endif +#endif namespace boost { namespace geometry { @@ -56,6 +58,8 @@ class multi_linestring : public Container > { BOOST_CONCEPT_ASSERT( (concept::Linestring) ); +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST + typedef Container > base_type; public: @@ -84,6 +88,7 @@ public: // } //#endif +#endif #endif }; diff --git a/include/boost/geometry/geometries/multi_point.hpp b/include/boost/geometry/geometries/multi_point.hpp index 839c1c304..a5e64bb91 100644 --- a/include/boost/geometry/geometries/multi_point.hpp +++ b/include/boost/geometry/geometries/multi_point.hpp @@ -19,14 +19,16 @@ #include #include -#include #include #include +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST +#include #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST #include #endif +#endif namespace boost { namespace geometry { @@ -72,6 +74,7 @@ public : : base_type(begin, end) {} +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST /// \constructor_initializer_list{multi_point} @@ -92,6 +95,7 @@ public : // } //#endif +#endif #endif }; diff --git a/include/boost/geometry/geometries/multi_polygon.hpp b/include/boost/geometry/geometries/multi_polygon.hpp index 0d4d64e2b..51fcf235f 100644 --- a/include/boost/geometry/geometries/multi_polygon.hpp +++ b/include/boost/geometry/geometries/multi_polygon.hpp @@ -19,14 +19,16 @@ #include #include -#include #include #include +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST +#include #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST #include #endif +#endif namespace boost { namespace geometry { @@ -55,6 +57,8 @@ class multi_polygon : public Container > { BOOST_CONCEPT_ASSERT( (concept::Polygon) ); +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST + typedef Container > base_type; public: @@ -83,6 +87,7 @@ public: // } //#endif +#endif #endif }; diff --git a/include/boost/geometry/geometries/polygon.hpp b/include/boost/geometry/geometries/polygon.hpp index dfa1866d5..5f2e87a11 100644 --- a/include/boost/geometry/geometries/polygon.hpp +++ b/include/boost/geometry/geometries/polygon.hpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -28,9 +27,12 @@ #include #include +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST +#include #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST #include #endif +#endif namespace boost { namespace geometry { @@ -89,6 +91,8 @@ public: inline ring_type& outer() { return m_outer; } inline inner_container_type & inners() { return m_inners; } +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST + /// \constructor_default{polygon} inline polygon() : m_outer() @@ -124,6 +128,7 @@ public: // } //#endif +#endif #endif /// Utility method, clears outer and inner rings diff --git a/include/boost/geometry/geometries/ring.hpp b/include/boost/geometry/geometries/ring.hpp index df875569e..502c95d75 100644 --- a/include/boost/geometry/geometries/ring.hpp +++ b/include/boost/geometry/geometries/ring.hpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -28,9 +27,12 @@ #include +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST +#include #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST #include #endif +#endif namespace boost { namespace geometry { @@ -78,6 +80,7 @@ public : : base_type(begin, end) {} +#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST /// \constructor_initializer_list{ring} @@ -98,6 +101,7 @@ public : // } //#endif +#endif #endif }; diff --git a/test/geometries/Jamfile.v2 b/test/geometries/Jamfile.v2 index 9999c7280..c09ff95ad 100644 --- a/test/geometries/Jamfile.v2 +++ b/test/geometries/Jamfile.v2 @@ -25,6 +25,6 @@ test-suite boost-geometry-geometries # custom_linestring_test_fail_clear #] [ run custom_linestring.cpp ] - [ run geometries.cpp ] + [ run geometries.cpp : : : BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST ] [ run segment.cpp ] ;