Topic: std::bind2nd for function taking reference?
Author: Thomas Maeder <maeder@glue.ch>
Date: 2000/01/13 Raw View
Scott Meyers schrieb:
>
> > The binder2nd constructor (=A720.3.6.3) takes its second argument by
> > reference, which isn't possible if the base type is a reference (or
> > pointer) already.
>
> I don't see why a pointer would be a problem. There's nothing wrong with
> a reference to a pointer.
You are right.
So the original question is reduced to methods taking a reference.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: smeyers@aristeia.com (Scott Meyers)
Date: 2000/01/07 Raw View
On 20 Dec 99 14:16:09 GMT, Thomas Maeder wrote:
> The binder2nd constructor (=A720.3.6.3) takes its second argument by
> reference, which isn't possible if the base type is a reference (or
> pointer) already.
I don't see why a pointer would be a problem. There's nothing wrong with a
reference to a pointer.
Scott
--
Scott Meyers, Ph.D. smeyers@aristeia.com
Software Development Consultant http://www.aristeia.com/
Visit http://meyerscd.awl.com/ to demo the Effective C++ CD
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Thomas Maeder <maeder@glue.ch>
Date: 1999/12/20 Raw View
The following program compiles:
#include <functional>
void foo(int,int) { }
int main()
{
int s =3D 0;
std::bind2nd(std::ptr_fun(&foo),s);
}
This, however, doesn't
#include <functional>
void foo(int,int&) { }
int main()
{
int s =3D 0;
std::bind2nd(std::ptr_fun(&foo),s);
}
The binder2nd constructor (=A720.3.6.3) takes its second argument by
reference, which isn't possible if the base type is a reference (or
pointer) already.
If I add
namespace std
{
template <class S, class T, class A>=20
class ptr_fun1ref_t : public binary_function<T,A,S>
{
S (*pf)(T,A&);
public:
explicit ptr_fun1ref_t(S (*p)(T,A&)) : pf(p) {}
S operator()(T p, A &a) const { return (*pf)(p,a); }
};
template <class S, class T, class A>=20
inline ptr_fun1ref_t<S,T,A> ptr_fun(S (*pf)(T,A&))
{
return ptr_fun1ref_t<S,T,A>(pf);
}
}
(knowing that I'm not allowed to do that), the above program compiles
again.
Is this a defect in the Standard C++ Library to me, or was it deliberatel=
y
left out because it's not needed for the library itself?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]