I wrote the Point class (in 3d space) and wondered what would be the best way to create a starting point. Here is the base class (taken from Andyβs example, just in case someone wondered what the main implementation was):
struct Point { constexpr Point(double x_, double y_, double z_) : x(x_), y(y_), z(z_) { } double x; double y; double z; };
The first way to have the origin would be to define a constexpr variable:
constexpr Point origin = { 0.0, 0.0, 0.0 };
The second would be to define a new type and overload algorithms so that they can benefit from optimizations when computing from the beginning (let's say I wrote a constexpr constructor for Point ):
struct Origin: public Point { constexpr Origin(): Point(0.0, 0.0, 0.0) {} }; constexpr Origin origin;
While the first method seems simpler and less error prone, I would like to know if the second one looks like a good idea, and if I have some pitfalls that I have not seen.
EDIT: Thinking about link libraries, I noticed that CGAL used something like this:
class Origin {}; const Origin ORIGIN;
Jehan source share