[phoenix] lazy function to reference or const reference

Hi, Is it possible to use references as the type of the function wrapped by lazy function. The reason I need this is because I need to instatiate a lazy function inside a class and to a class while the class does not have yet a complete definition. The application may sound exotic but I see no intrinsic limitation why the following doesn't work. If this is not possible because an intrinsic limitation of phoenix, is there a workaround? -- Thanks -- Alfredo ... is_odd_impl is defined as in http://svn.boost.org/svn/boost/sandbox/SOC/2010/phoenix3/libs/phoenix/doc/ht... #include<iostream> #include<boost/phoenix/core.hpp> #include<boost/phoenix/function.hpp> using namespace std; using boost::phoenix::arg_names::arg1; int main(){ int cuatro = 4.; is_odd_impl ioi; clog << ioi(cuatro) << endl; boost::phoenix::function<is_odd_impl> fioi; clog << fioi(arg1)(cuatro) << endl; boost::phoenix::function<is_odd_impl&> fioi_ref(ioi); clog << fioi_ref(arg1)(cuatro) << endl; //doesn't compile !!! boost::phoenix::function<is_odd_impl const&> fioi_cref(ioi); clog << fioi_cref(arg1)(cuatro) << endl; //doesn't compile !!! return 0; } example error message: usr/include/boost/phoenix/core/preprocessed/expression_10.hpp:101:17: error: invalid initialization of reference of type ‘const is_odd_impl&’ from expression of type ‘const boost::proto::result_of::make_expr<boost::proto::tag::function, boost::phoenix::default_domain_with_basic_expr, const is_odd_impl, const boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::argument<1> >, 0l>
, void, void, void, void, void, void, void, void, void, void>::type’

On Monday, April 04, 2011 10:29:57 AM alfC wrote:
Hi,
Is it possible to use references as the type of the function wrapped by lazy function. The reason I need this is because I need to instatiate a lazy function inside a class and to a class while the class does not have yet a complete definition. The application may sound exotic but I see no intrinsic limitation why the following doesn't work. If this is not possible because an intrinsic limitation of phoenix, is there a workaround?
I messed up in the type calculation ;) Thanks for reporting, the issue is now fixed on trunk.
-- Thanks -- Alfredo
... is_odd_impl is defined as in
http://svn.boost.org/svn/boost/sandbox/SOC/2010/phoenix3/libs/phoenix/doc/ht... Please update your copy of Phoenix. Phoenix V3 is now in the boost trunk, the sandbox/SOC version will not get fixed anymore. https://svn.boost.org/svn/boost/trunk/libs/phoenix/doc/html/phoenix/starter_...

On Apr 4, 2:53 am, Thomas Heller <thom.hel...@googlemail.com> wrote:
I messed up in the type calculation ;) Thanks for reporting, the issue is now fixed on trunk.
great, thanks, now it works. What I wanted to achieve was a function class that is at the same time a lazy function, A a; a(5.); //calls the usual operator() a(arg1 + 1.); // build a phoenix expression maybe implemented like below. However I can't, the compilation error was usr/include/boost/type_traits/is_abstract.hpp:72:4: error: incomplete type ‘A’ not allowed. Is there an elegant way to achieve this? -- Thanks -- Alfredo #include<boost/phoenix/core.hpp> #include<boost/phoenix/function.hpp> struct A : boost::phoenix::function<A&> { A() : boost::phoenix::function<A&>(*this){} template <typename Arg> struct result{ typedef double type; }; using boost::phoenix::function<A&>::operator(); template<typename Arg> double operator()(Arg arg1) const{ return 5.; } };
participants (2)
-
alfC
-
Thomas Heller