Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscript operator[] error with Boost C++ Phoenix user-defined argument

With an existing Boost Phoenix (placeholder) argument, such as _1, I can use the array/subscript operator. For example, the following excerpt will display a 1.

int arr[4] = {1,2,3,4};
std::cout << _1[0](arr) << std::endl;

However, if I define my own placeholder argument:

phoenix::actor<phoenix::expression::argument<1>::type> const my_1 = {{}};

though it works fine unadorned (the following outputs a 7):

std::cout << my_1(7) << std::endl;

if I attempt to use the subscript operator (as above):

std::cout << my_1[0](arr) << std::endl;

I get many errors; in summary, with G++ 4.7.2, template argument deduction fails; with Clang 3.2, I'm told that a function cannot return an array type.

How can I make my Phoenix placeholder argument support the subscript operator?

like image 520
user2023370 Avatar asked Sep 01 '26 10:09

user2023370


1 Answers

Just get rid of the actor part and it works fine:

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

int main()
{
    namespace phx = boost::phoenix;

    phx::expression::argument<1>::type const my_1 = {{{}}};
    int arr[4] = { 1, 2, 3, 4 };
    std::cout << my_1[0](arr) << '\n';
}

Online demo

like image 174
ildjarn Avatar answered Sep 04 '26 00:09

ildjarn