Boost logo

Boost :

Subject: Re: [boost] [gil] What is the status of the Gil extension numeric?
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-03-14 13:46:07


2013/3/14 Christian Henning <chhenning_at_[hidden]>

> Hi Kris,
>
> >
> > Christian, you mean the io extension, do you? I don't see numeric in
> trunk.
>
> I have yet to add it. Probably this weekend.
>
> > I also have some comments about point2 from gil/utilities.hpp:
> >
> > {{{
> > template <typename T>
> > class point2 {
> > public:
> > [...]
> > //--- these 3 functions don't add anything, do they? why not remove them
> > rely on defaults?
> > point2(const point2& p) : x(p.x), y(p.y) {}
> > ~point2() {}
> > point2& operator=(const point2& p) { x=p.x; y=p.y; return
> > *this; }
>
> You mean that these functions are usually generated by the compiler?
>

I wouldn't say 'usually' ;-) I'd say they are guaranteed to be generated,
and do the same thing, as the ones provided above ;-)

> [...]
> > point2& operator/=(double t) { x/=t; y/=t; return
> > *this; }
> > T x,y;
> > [...]
> > };
> >
> > [...]
> > template <typename T> GIL_FORCEINLINE
> > point2<double> operator/(const point2<T>& p, double t) { return
> t==0 ?
> > point2<double>(0,0):point2<double>(p.x/t,p.y/t); }
> > /// \ingroup PointModel
> > template <typename T> GIL_FORCEINLINE
> > point2<T> operator*(const point2<T>& p, std::ptrdiff_t t) { return
> > point2<T>(p.x*t,p.y*t); }
> > /// \ingroup PointModel
> > template <typename T> GIL_FORCEINLINE
> > point2<T> operator*(std::ptrdiff_t t, const point2<T>& p) { return
> > point2<T>(p.x*t,p.y*t); }
> > }}}
> >
> > So point2 has miltiplication by ptrdiff_t, and division by double. This
> was
> > very confusing for me - that multiplying point2<double> by 0.5 gave me
> > point2(0,0).
> >
> > But this probably is as it is for a reason, so I'm not sure if my idea
> for
> > fixing this is the right way to go: I'd just add * and / for point2<T>
> and
> > T, and add multiplication by double. I'd be happy to try to implement
> this
> > change with some tests, if you think it's the right way to go ;-)
>
> I don't quite get the reasoning myself. I would just use T instead of
> std::ptrdiff_t or double. This way the user has to make sure what he
> is passing. Maybe someone else can shed some light?

That would be fine with me. But * and / by double for integral T's might be
useful, and since /double is here, I suspect removing it can break some
code...

Regards,
Kris


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