
Giovanni Piero Deretta wrote:
On Wed, Jul 2, 2008 at 4:12 AM, Joel de Guzman <joel@boost-consulting.com> wrote:
Giovanni Piero Deretta wrote:
- Last time I checked Phoenix only had a monomoprhic bind. If you have polymorphic functions you have to convert them to lazy functions. I think that adding a polymorphic bind (like lambda shouldn't be hard). Boost.Lambda has polymorphic bind? How can it do that? Bind is inherently monomorphic. What am I missing?
Uh? Even C++0x bind is polymorphic:
struct plus_t { template<class A, class B> [] operator()(A a, B b) -> decltype(a + b) { return a + b; } };
auto plus = std::bind(plus_t(), _1, _2);
int a = plus(1, 2);
std::string b = plus(std::string("hello"), std::string("world"));
With appropriate 'sig' magic in plus_t you can do the same thing with boost.lambda (but not with boost.bind). Or we are talking about different kind of polymorphism?
Uh oh. I misunderstood you. Well, in that case, phoenix has polymorphic bind for function objects. It is only monomorphic when binding free functions and member functions. Example (this example is in the distro): struct sqr { template <typename Arg> struct result { typedef Arg type; }; template <typename Arg> Arg operator()(Arg n) const { return n * n; } }; ... BOOST_TEST(bind(sqr(), arg1)(i5) == (i5*i5)); (Note that the return type deduction was from the original phoenix 1.0 and predates result_of. This is changed in the latest version). Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net