Subscript operator[] error with Boost C++ Phoenix user-defined argument
boost, boost-phoenix, boost-proto, c++, templates
Solution
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
Problem
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?