I'd like to provide an API which accepts a user-defined Boost Phoenix lambda. Unlike a C++11 lambda, a Phoenix lambda is polymorphic.
I am able to use the []
operator of a lambda argument. The following snippet will output the first element of array arr
:
int arr[4] = {1,2,3,4};
cout << _1[_2](arr,0) << endl;
How can I allow the user to access member data or methods of a lambda argument? The following code snippet, for example, fails to compile; giving: error: ‘const type’ has no member named ‘x’
struct vec2 { float x,y; };
vec2 v2{1,2};
cout << ((_1).x)(v2) << endl;