c++ - Using Boost.Phoenix's operator ->* -
i'm playing around phoenix v3 trying figure out whether should standardize on instead of current mix of bind , lambda. documentation got impression should possible simplify expressions.
currently i'm stuck on usage of ->* operator in combination stl algos. following compile (visual studio 2008 sp1) not give expected output:
#include <algorithm> #include <iostream> #include <vector> #include <boost/mem_fn.hpp> #include <boost/phoenix.hpp> using namespace std; using namespace boost; using namespace boost::phoenix; using namespace boost::phoenix::arg_names; struct { void f() const { cout << "a"; }; }; struct b { a() { return a(); }; }; int main() { vector<a> va(1); for_each(va.begin(), va.end(), bind(mem_fn(&a::f), arg1)); for_each(va.begin(), va.end(), arg1->*&a::f); vector<b> vb(1); for_each(vb.begin(), vb.end(), bind(mem_fn(&a::f), bind(mem_fn(&b::a), arg1))); return 0; }
running example print out 'a' twice, both times bind-based loops. here questions:
- what should change in order have operator-based loop call a::f?
- how change double-bind loop using operators?
- anyone know why vs2008 complaining when don't specify mem_fn in these cases? warning c4180 (qualifier applied function type has no meaning; ignored).
thanks in advance insights.
i not @ phoenix think cannot use ->* operator way want use.
if change example
... vector<a*> va; va.push_back(new a); for_each(va.begin(), va.end(), bind(mem_fn(&a::f), arg1)); for_each(va.begin(), va.end(), (arg1->*&a::f)()); ...
you 2 times a. in examples found examples pointers guess can use phoenix ->* operator pointers. should ok operator ->* binds pointers.
spec in 5.5:
the binary operator ->* binds second operand, shall of type “pointer member of t” (where t completely-defined class type) first operand, shall of type “pointer t” or “pointer class of t unambiguous , accessible base class
Comments
Post a Comment