|
Boost : |
From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-01-07 10:06:20
>> > Oh, here's another feature I like for my points: indexability (I like
>> > to be able to access the coordinates by index). That allows
>> > programmatic selection of orientation for things like scrollbars.
>> > Indexability is of course unusable when the types of x and y differ.
>> > OTOH this is definitely a corner case. I have no strong opinion on the
>> > topic.
>>
>> We can provide generic version of classes with two template parameters
>> (and without indexability) and a specialization for case T1==T2 with
>> operator[]. I think it will be reasonable solution.
>
> I have some sympathy with the overdesign comment, but it may be worthwhile
> considering the following for the generic version. It overloads the []
operator
> and uses function overloading to achieve programmatic selection on orientation
> etc. Obviously, as it's a compile time thing, it can't be used for looping
over
> (x .. y) - but that shouldn't be a problem for just two coordinates.
>
> struct x_coord {} x;
> struct y_coord {} y;
>
> template <typename X, typename Y = X> class point
> {
> public:
>
> X operator[]( x_coord ) { return x_; }
> Y operator[]( y_coord ) { return y_; }
>
> private:
>
> X x_;
> Y y_;
> };
>
> class latitude {};
> class longitude {};
>
> void process_coord( latitude ) {}
> void process_coord( longitude ) {}
>
>
> void test()
> {
> point<latitude, longitude> p;
>
> latitude lat = p[x];
> longitude lon = p[y];
>
> process_coord( p[x] );
> process_coord( p[y] );
> }
>
> Gavin
>
> --
> Gavin Collings
> gcollings_at_[hidden]
Yep, this is a fine design. The question remains, though: should we restrain
ourselves, and say "if you need this specialized application, you should
make your own wrapper?" After all, this kind of orientation flipping is just
a simple case of generalized transformation using matrix multiplication.
Since our geometry proposal is strictly 2D and doesn't include any other
facilities for transformation so far. The more I think about it, the more
I'm sorry I mentioned it.
-Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk