CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.87k stars 1.38k forks source link

Move enable CGAL types #34

Open bo0ts opened 9 years ago

bo0ts commented 9 years ago

When working with CGAL in C++11 and upwards one of the biggest issues is that most types cannot be efficiently moved even if they should. Users end up writing code that works around that instead of using the straight forward approach. This primarily affects types which carry large geometric structures.

A non-exhaustive list:

lrineau commented 9 years ago

Who could spend time on that task, among the @CGAL/developers ?

efifogel commented 9 years ago

I'm not volunteering my self, but could you give a specific example.


//) o /__ // (__ ( ( ( (/ (/-(-'(/ /

On Wed, Apr 8, 2015 at 2:55 PM, Laurent Rineau notifications@github.com wrote:

Who could spend time on that task, among the @CGAL/developers https://github.com/orgs/CGAL/teams/developers ?

— Reply to this email directly or view it on GitHub https://github.com/CGAL/cgal/issues/34#issuecomment-90890710.

bo0ts commented 9 years ago

@efifogel Polygon_2 is a very simple example: it is templated by the container. All possible containers support move construction. For some unknown reason a dubious copy-constructor is provided, which prevents generation of a move constructor etc. Fixing this would make it possible to cheaply pass a Polygon_2 by value.

lrineau commented 9 years ago

Everybody should know something about the C++ Rule of 3 (in C++98), that became Rule of 5 or Rule of 0, in C++11:

I personally prefer the Rule of 0: do not deal with resources yourself, but we could apply the Rule of 5 for our own containers.

bo0ts commented 9 years ago

One problem is that we need to identify classes with unnecessary constructors and sometimes even destructors. They didn't do much harm in C++03 but are actively harmful in C++11.

I guess one starting point is to raise awareness and fix it as we go along.

lrineau commented 9 years ago

Le Friday 10 April 2015 05:34:23 Philipp Moeller a écrit :

One problem is that we need to identify classes with unnecessary constructors and sometimes even destructors. They didn't do much harm in C++03 but are actively harmful in C++11.

I guess one starting point is to raise awareness and fix it as we go along.

Could there be a way to modify the test suite to check the extra copies?

(My policy in CGAL is that anything that is not tested can be considered as broken, or having the potential to break after a while.)

Laurent Rineau, PhD R&D Engineer at GeometryFactory http://www.geometryfactory.com/ Release Manager of the CGAL Project http://www.cgal.org/

bo0ts commented 9 years ago

It is hard to test for MoveConstructible, since it will fall-back on CopyConstructible. This means that std::is_move_constructible and the related type traits will only tell you if construction from an rvalue is OK, but not if it is efficient.

One way can be a hand written test like:

X x; // fill x with stuff
X y = std::move(x);
// now check if x is empty or something

This only works if you know something about X and its invariants when being moved from, so you can only do this on a case-by-case basis.

mglisse commented 9 years ago

Yes, case by case seems the only way to test (I wouldn't bother). is_nothrow_move_constructible is often the easiest test (since very often copy constructors throw and move constructors don't).

sgiraudot commented 8 years ago

If I understand correctly, the conclusion is to "raise awareness and fix it as we go along". Does everyone agree on this?

If so, I suggest we add a paragraph about this somewhere in the developer manual (with the links that @lrineau provided about the rules of 5 and 0) and close the issue. It seems unrealistic to review all classes of CGAL at once, so we should just expect new issues about this problem and fix them when they are raised.

lrineau commented 8 years ago

Let's say that I will raise the topic at next developers meeting. I can probably present the topic, problems, and solutions with a few slides.

MoniqueTeillaud commented 7 years ago

Did we discuss it in Zurich?

lrineau commented 7 years ago

No. Nobody added it in the list of topics. It will be in the next one.

lrineau commented 6 years ago

The very recent issue #2925 asks for move-semantic in AABB_tree. C++11 more that 10 years old now (even before 2011 it was available under the name C++0x), and CGAL should do something!