1

The Boost Phoenix documentation here indicates that I can create my own (lambda) arguments instead of _1/arg1, _2,arg2 etc. So, starting with code like this:

#include <iostream>
#include <boost/phoenix.hpp>

int main(int argc, char *argv[]) {
  std::cout << (boost::phoenix::arg_names::_1)(17) << std::endl;
  return 0;
}

...which outputs 17, I'm aiming for a first step of using myarg1. The documentation recommends that I first #include <boost/spirit/home/phoenix/core/argument.hpp>. Doing this (G++ 4.7.2), however, results in a series of compilation errors starting with: error: redefinition of ‘struct boost::phoenix::detail::error_expecting_arguments’.

Without the arguments.hpp file included, I notice that I can declare variables of type boost::phoenix::argument<0>. When I try to declare a variable of the crucial type, boost::phoenix::actor< boost::phoenix::argument<0> >, however, I again receive numerous errors; this time starting with: error: no type named ‘proto_base_expr’. How can I define my own lambda arguments?

Jason R
  • 11,159
  • 6
  • 50
  • 81
user2023370
  • 10,488
  • 6
  • 50
  • 83
  • 3
    You can use 2 versions of phoenix which are incompatible with each other. v2 lives in `boost/spirit/home/phoenix`, v3 in `boost/phoenix`. If you try to mix headers you get redefinition errors. So the header you wanted to use is `boost/phoenix/core/argument.hpp` and that one is included when you use the global include. In order to declare an actor you can use `phx:actor::type> my_actor` where N is the position of the argument you want to use starting at 1. Maybe `my_actor` should be declared const but, in my limited testing, it doesn't seem to change anything. –  Feb 25 '13 at 06:23
  • Thanks @llonesmiz! I missed your comment about starting at 1, but now it works fine. If anyone would like to provide that as an answer, they can receive the points. – user2023370 Feb 25 '13 at 10:16
  • 1
    @llonesmiz : `const` allows for static initialization since the types involved are all POD types. I.e., it's a harmless micro-optimization. – ildjarn Mar 14 '13 at 20:04
  • 1
    `phx::expression::argument::type` also works, and allows me to use the subscript operator; as discussed [here](http://stackoverflow.com/questions/15397899/subscript-operator-error-with-boost-c-phoenix-user-defined-argument). Is there a disadvantage to this? – user2023370 Mar 14 '13 at 20:44

0 Answers0