mem_fun family (for_each, bind..)

Levente Farkas !spam-lfarkas@mindmaker.hu
Sat Aug 7 10:38:00 GMT 1999


Gary Granger wrote:
> 
> The draft standard I have lists the bind2nd declaration as follows:
> 
>     template <class Operation, class T>
>       binder2nd<Operation> bind2nd(const Operation&, const T&);
> 
> It looks like the type 'double' you are passing cannot be used since it is
> not constant.  I replaced your reference with a pointer and it compiled and
> ran with no problems:
> 
> Across the ether fly the words of Levente Farkas:
> ...
> >   void f(double& d) const { ++d; }
> void f(double *d) const { ++(*d); }
> ...
> >                   std::bind2nd(std::mem_fun(&A::f), d));
>                     std::bind2nd(std::mem_fun(&A::f), &d));
> 
> > ...
> > ms's compiler don't support it), but this simple example can't compile even
> > on the latest egcs/gcc - 2.95!
> > or am I wrong ?
> 
> If you are not sure whether this "simple example" complies with the
> standard, then perhaps it is not so simple, and you should instead let the
> newsgroups answer the STL question *before* asking the bug question.

you've got right, the problem is not just with the implementation.
1. there's a problem in the standard : bind2nd should have to be
     template <class Operation, class T>
       binder2nd<Operation> bind2nd(Operation, T);
   since it's a template and in this case if T == const double & than
   it don't need another const or &, what's more it can work in all case.
2. the implementations are bad, since it's not specialized to be a void
   Operation and since void in not real type (another bug in the standard
   you can't return with void) so you can't return with a void function
   in binder2nd's operator().
   ps. in the sgi's stl the mem_fun family is specialized, but the bind2nd
   isn't (in the ms's stl you can't specialized

 -- Levente


More information about the Libstdc++ mailing list