Boost logo

Boost Users :

Subject: [Boost-users] [phoenix] lazy function to reference or const reference
From: alfC (alfredo.correa_at_[hidden])
Date: 2011-04-04 04:29:57


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/html/phoenix/starter_kit/lazy_functions.html
#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’


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