Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2008-03-25 18:13:48


Bruno Lalande wrote:
>> - While generalized point types (2D vs. 3D and XY vs. lat/lon) are OK,
>> it is often extremely useful in graphics code to make your objects fit
>> the underlying representation of an externally defined structure (such
>> as POINT type in Win32) -- for example by publicly or privately
>> inheriting from it.

Ouch, no!

>> This lets you use e.g. vectors of points as
>> arguments for system APIs. Can be done by adding an extra template
>> argument (with a default) to point<> and moving most of the
>> implementation details into a traits class.
>
>
> In my understanding, the goal of point is not to wrap your own point
> structure but to be replaced with it, provided that it satisfies the same
> concept : value<>() functions, coordinate_type, coordinate_count... If you
> do so, all the algorithms are supposed to work with your structure.

This has been well discussed many times: make Point a concept and
allow many models of the Point concept. It is a mistake to have
a single do-it-all point class. What if I want a 2 dimensional
point with a short for x and a long for y? Your class can never
satisfy all possibilities. The best strategy is to allow for
multiple point models be usable in your algorithms. Example:

     liba::point p1;
     libb::point<int> p2;
     POINT p3; // MFC

     cout << distance(p1, p2) << endl;
     cout << distance(p2, p3) << endl;

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk