Opened 10 years ago
Last modified 7 years ago
#8362 new Support Requests
Move ctor or assignment for boost::geometry::model::ring?
Reported by: | Owned by: | Mateusz Loskot | |
---|---|---|---|
Milestone: | To Be Determined | Component: | geometry |
Version: | Boost 1.57.0 | Severity: | Cosmetic |
Keywords: | convert, move, assign | Cc: |
Description
Hi, I have this clumsy piece of code:
if( !vecpt.empty() ) { emplace_back( polygon_type() ); static_cast< std::vector< _TPoint< T > >& >( back().outer() ) = std::move(vecpt); }
which actually should be written like this:
boost::geometry::convert( polygon_type::ring_type( std::move(vecpt) ), *this );
but unfortunately this kind of conversion does not work. Did I make a mistake in my above statement, or is this not (yet) supported? If the latter, do you plan on adding support for this at some point? Thanks!
Volker
Change History (8)
comment:1 by , 10 years ago
Owner: | changed from | to
---|
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Barend,
The requested move semantic is one issue, but unless I'm missing something, is the ring model supposed to be constructible directly from compatible container of compatible points? The extension constructor in ring takes iterators only, not container.
Obviously, this does not compile:
#include <vector> #include <boost/geometry.hpp> #include <boost/geometry/geometries/ring.hpp> #include <boost/geometry/geometries/point_xy.hpp> int main() { typedef boost::geometry::model::d2::point_xy<double> point; typedef boost::geometry::model::ring<point> ring; std::vector<point> r1; ring r2; boost::geometry::convert(r1, r2); return 0; }
Shall I extend the ring to make it constructible from the container too?
follow-up: 5 comment:4 by , 10 years ago
OK for me to add a constructor with a container with its point types. It was not there because vector/deque do not have it neither.
Does this solve the whole issue? In the reported problem, std::move seems not necessary in the call to convert...
comment:5 by , 10 years ago
Replying to mloskot:
The requested move semantic is one issue, but unless I'm missing something, is the ring model supposed to be constructible directly from compatible container of compatible points? The extension constructor in ring takes iterators only, not container.
Replying to barendgehrels:
OK for me to add a constructor with a container with its point types. It was not there because vector/deque do not have it neither.
Although to me this seems to be a desirable extension, I am not saying that this is the only way to solve the issue. Leaving constructors alone, you could alternatively overload the convert algorithm to support conversion from vector-of-points to (Multi-)Polygon:
boost::geometry::convert( std::move(vecpt), *this );
My suggestion to call convert by way of constructing a ring_type first was merely based on my observation that convert already supports conversion from Ring to Polygon.
Replying to barendgehrels:
Does this solve the whole issue?
There are two more niceties I would like to suggest to solve the whole issue:
- In boost 1.52.0, convert supports Ring to Polygon conversion, but does not support (any Geometry that supports conversion to Polygon) to Multi-Polygon conversion. Is this by design, or is this considered a missing feature?
- While we are at it, is it intentional that I have to guard the conversion with "!vecpt.empty()"? I don't see a problem with creating a Ring from an empty vector-of-points and convert that to a Polygon that consist of empty vectors.
Replying to barendgehrels:
In the reported problem, std::move seems not necessary in the call to convert...
Can you explain why you think std::move is unnecessary there? It may in fact be useless if there is any link in the chain of calls that does not support move semantics, but from my perspective I should still put it there to enable move semantics where it is supported. There seems to be consensus that the compiler must not automatically turn a copy into a move. Thus I think I have to be explicit about my intent to use move semantics.
comment:6 by , 8 years ago
Version: | Boost 1.52.0 → Boost 1.57.0 |
---|
comment:7 by , 8 years ago
As far as I understand, I still cannot write an expression like this in 1.57.0:
boost::geometry::convert( polygon_type::ring_type( tc_move(vecpt) ), *this );
I'm not saying that this is a major problem or anything, just updating the ticket.
Some additional information. *this is a multi-polygon with the following definition:
The polygon definition is based on our _TPoint<T> type which is declared for use with boost::geometry as follows:
Similarly, we have our own _TRect<T> type which we plug into boost::geometry:
In our code, these classes are instantiated with template parameter T being either int or double. We have a lot of use for int-based geometry calculations.
With these geometry types we successfully call many algorithms from boost::geometry, e.g.,
but the following does not seem to work (as of boost 1.52.0):