Boost logo

Boost Users :

Subject: [Boost-users] boost::proto user guide - compile error creating a lazy function
From: Tom Babbin (ctb070_at_[hidden])
Date: 2009-09-19 08:51:01


Hi,

I am going through proto user guide. I am getting compiling error for the
following piece code (it's pretty much copy and pasted from the guide). I
used 1.40 and gcc.

#include <iostream>
#include <boost/mpl/int.hpp>
#include <boost/proto/core.hpp>
#include <boost/proto/context.hpp>
#include <boost/proto/debug.hpp>
#include <cmath>
#include <vector>

namespace proto = boost::proto;

template<int I> struct placeholder {};

// Define some placeholders
proto::terminal< placeholder< 1 > >::type const _1 = {{}};
proto::terminal< placeholder< 2 > >::type const _2 = {{}};

struct calculator_context
  : proto::callable_context< calculator_context const >
{
    // Values to replace the placeholders
    std::vector<double> args;

    // Define the result type of the calculator.
    // (This makes the calculator_context "callable".)
    typedef double result_type;

    // Handle the placeholders:
    template<int I>
    double operator()(proto::tag::terminal, placeholder) const
    {
        return this->args[I];
    }
};

// Define a pow_fun function object
template<int Exp>
struct pow_fun
{
    typedef double result_type;
    double operator()(double d) const
    {
        return std::pow(d, Exp);
    }
};

// Define a lazy pow() function for the calculator DSEL.
// Can be used as: pow< 2 >(_1)
template<int Exp, typename Arg>
typename proto::function<
    typename proto::terminal<pow_fun<Exp> >::type
  , Arg const &
>::type
pow1(Arg const &arg)
{
    typedef
        typename proto::function<
            typename proto::terminal<pow_fun<Exp> >::type
          , Arg const &
>::type
    result_type;

    result_type result = {{{}}, arg};
    return result;
}

int main()
{
    calculator_context ctx;
    ctx.args.push_back(3);

    std::cout << boost::proto::eval( pow1<2>( _1 ), ctx );

    return 0;
}

The error says:

calc2.cpp: In function 'int main()':
calc2.cpp:116: error: no matching function for call to
'eval(boost::proto::exprns_::expr<boost::proto::tag::function,
boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<pow_fun<2> >, 0l>, const
boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<placeholder<1> >, 0l>&>, 2l>,
calculator_context&)'
/auto/cigprod/spg/lx86_64/opt/boost_1_40_0/boost/proto/eval.hpp:91: note:
candidates are: typename boost::proto::result_of::eval<Expr, Context>::type
boost::proto::eval(Expr&, Context&) [with Expr =
boost::proto::exprns_::expr<boost::proto::tag::function,
boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<pow_fun<2> >, 0l>, const
boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<placeholder<1> >, 0l>&>, 2l>, Context =
calculator_context]
/auto/cigprod/spg/lx86_64/opt/boost_1_40_0/boost/proto/eval.hpp:100: note:
typename boost::proto::result_of::eval<Expr, Context>::type
boost::proto::eval(Expr&, const Context&) [with Expr =
boost::proto::exprns_::expr<boost::proto::tag::function,
boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<pow_fun<2> >, 0l>, const
boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<placeholder<1> >, 0l>&>, 2l>, Context =
calculator_context]

Thanks.

-- 
View this message in context: http://www.nabble.com/boost%3A%3Aproto-user-guide---compile-error-creating-a-lazy-function-tp25516502p25516502.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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