
I am trying to decide whether the argument type to a function taking a proto expression should be "const T&" or "T&" based on the expression itself. Suppose the expression was "_1 = _2 + 1" I want the first argument to a function, say FOO, to be T& and second argument to be const T&. I write a transform argtype<int, typename> as follows : #include <boost/proto/proto.hpp> #include <boost/mpl/int.hpp> #include <iostream> struct arg_tag {}; namespace proto = boost::proto; namespace mpl = boost::mpl; using namespace std; template<int N> struct arg : proto::or_<proto::nullary_expr<arg_tag, mpl::int_<N> > > {}; template<typename T> struct readonly : proto::callable { template<typename Sig> struct result; template<typename This> struct result<This()> { typedef const T& type; }; }; template<typename T> struct readwrite : proto::callable { template<typename Sig> struct result; template<typename This> struct result<This()> { typedef T& type; }; }; template<int N, typename T> struct argtype : proto::or_< proto::when<proto::assign<arg<N>, proto::_>, readwrite<T>()> , proto::otherwise<readonly<T>()>
{}; proto::nullary_expr<arg_tag, mpl::int_<0> >::type const _1 = {{}}; proto::nullary_expr<arg_tag, mpl::int_<1> >::type const _2 = {{}}; template<typename E> void foo(const E &e) { cout << typeid(typename boost::result_of<argtype<0,int>(const E&)>::type).name() << "\n"; } int main() { foo(_1=_1+1); return 0; } I expected the typeid printed out by the foo function to be equivalent to "int&" whereas I get "readwrite<int>". Any clues on where I am going wrong? Thanks, Manjunath http://nonchalantlytyped.net/blog/musings/