|
Boost : |
From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-11-13 08:18:38
I'm still having a problem. I think I've whittled it down to the bare
minimum here:
#include <boost/bind.hpp>
#include <boost/utility.hpp>
template <class R>
struct converter
{
typedef void const* result_type;
void const* operator()(R const& x) const
{
return &x;
}
};
struct Y : boost::noncopyable
{
virtual int f(const char*) = 0;
virtual int g(const char*, const char*) = 0;
};
struct X : Y
{
int f(const char*);
int g(const char*, const char*);
};
X x;
// OK:
const void* y = boost::bind(
converter<int>(),
boost::bind(
&Y::f,
boost::ref(*static_cast<Y*>(&x)), "goodbye")
)();
// Not OK:
const void* y1 = boost::bind(
converter<int>(),
boost::bind(
boost::bind(&Y::f, _1, _2), // <== changed this line only
boost::ref(*static_cast<Y*>(&x)), "goodbye")
)();
// Motivating Example:
const void* z = boost::bind(
converter<int>(),
boost::bind(
boost::bind(&Y::g, _1, _2, "hello"),
boost::ref(*static_cast<Y*>(&x)), "goodbye")
)();
----- Original Message -----
From: "Vladimir Voinkov" <voinkovv_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, November 13, 2001 5:19 AM
Subject: RE: [boost] bind/mem_fn problem
> I've compiled:
>
> int z = boost::bind(&X::f, _1, "hello")(x);
>
> Vladimir
>
> -----Original Message-----
> From: David Abrahams [mailto:david.abrahams_at_[hidden]]
> Sent: Tuesday, November 13, 2001 11:27 AM
> To: boost
> Cc: Peter Dimov
> Subject: [boost] bind/mem_fn problem
>
>
> The following short program doesn't compile:
>
> #include <boost/bind.hpp>
> struct X
> {
> int f(const char*);
> };
> X x;
> int y = boost::bind(&X::f, &x, _1)("hello"); // OK
> int z = boost::bind(&X::f, _1, "hello")(&x); // not OK
>
> Shouldn't it work?
>
> ===================================================
> David Abrahams, C++ library designer for hire
> resume: http://users.rcn.com/abrahams/resume.html
>
> C++ Booster (http://www.boost.org)
> email: david.abrahams_at_[hidden]
> ===================================================
>
>
>
> Info: http://www.boost.org Unsubscribe:
> <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk