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 as follows :
#include
#include
#include <iostream>
struct arg_tag
{};
namespace proto = boost::proto;
namespace mpl = boost::mpl;
using namespace std;
template<int N>
struct arg
: proto::or_ >
{};
template<typename T>
struct readonly
: proto::callable {
template<typename Sig>
struct result;
template<typename This>
struct result
{
typedef const T& type;
};
};
template<typename T>
struct readwrite
: proto::callable {
template<typename Sig>
struct result;
template<typename This>
struct result
{
typedef T& type;
};
};
template
struct argtype
: proto::or_<
proto::when, readwrite<T>()>
, proto::otherwise
{};
proto::nullary_expr >::type const _1 = {{}};
proto::nullary_expr >::type const _2 = {{}};
template<typename E>
void foo(const E &e)
{
cout << typeid(typename boost::result_of(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/