Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Phoenix Arguments Passing & Storage (-- Proper Type?) & Application to RValues -- Possible?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-02-14 21:57:48


On 02/14/2012 10:43 PM, Matt wrote:
> Hi there!
>
> I've got a question (two, in fact) regarding Arguments in Boost Phoenix.
>
> Assuming
> using boost::phoenix::arg_names::arg1;
> using boost::phoenix::val;
> using boost::phoenix::ref;
> using boost::phoenix::cref;
>
> Why does this compile (and works):
> int x = 1;
> int y = 2;
> std::cout << (arg1 % 2 == 1)(x) << '\n';
> std::cout << (arg1 % 2 == 1)(y) << '\n';
>
> while these fail to compile (with an extremely long diagnostic involving
> "boost::error_cant_deduce_type"):
>
> std::cout << (arg1 % 2 == 1)(1) << '\n';
> std::cout << (arg1 % 2 == 1)(2) << '\n';
>
> std::cout << (arg1 % 2 == 1)(val(1)) << '\n';
> std::cout << (arg1 % 2 == 1)(val(2)) << '\n';
>
> std::cout << (arg1 % 2 == 1)(cref(1)) << '\n';
> std::cout << (arg1 % 2 == 1)(cref(2)) << '\n';
>
> I run into this was while attempting to store an Arg. into a variable,
> i.e.,:
> auto f = (arg1 % 2 == 1);
> this works:
> std::cout << f(x) << '\n';
> std::cout << f(y) << '\n';
> while this fails:
> std::cout << f(1) << '\n';
> std::cout << f(2) << '\n';
> I'm guessing this must be for the same reason the above attempts fail.

You're using Phoenix v2, which doesn't support rvalues and also has many
type deduction problems.
Try v3.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net