Boost logo

Boost :

From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2001-05-16 13:51:12


> A slightly different version:
> template<class T>
> class constant : public unary_function<T, T> {
> T val;
> public:
> constant (T _val) :
> val (_val) {}
> T operator () (const T& x) const {
> return val;
> }
> };
>
I guess if this was to become a general purpose class I would prefer that a
constant reference be returned instead of a copy of the object. (Of course
that doesn't work for the native types but those could be specializations.)

> template<class T>
> class constant : public unary_function<T, T> {
> T val;
> public:
> constant (T _val) :
> val (_val) {}
> T const & operator () (const T& ) const {
> return val;
> }
> };
>
> template<>
> class constant<double> : public unary_function<double, double> {
> double val;
> public:
> constant (double _val) :
> val (_val) {}
> double operator () (double ) const {
> return val;
> }
> };
>
etc...

Or we could rename your class to "constant_copy"
But your example doesn't strike me as a common coding issue. I don't have a
problem with it becoming nominated as a boost component but I'm not sure
that it deserves "std" but of course that's just my personal view.

  -gary-

gary.powell_at_[hidden]


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