I realize that this may be more of a C++ language question rather than
proto specific. But I will ask it anyway. I wrote a transform that
infers some type information for the placeholders from an expression.
Say I have the expression _1 = _2 + 1, the transform can tell me that
the type of the first argument to operator() of the expression wrapper
should be "T &" and the type of the second should be "const T&". Here
is the transform (thanks to JoelF for his help on this) :
struct arg_tag {};
template<int N>
struct arg
: proto::or_ >
{};
template<typename T>
struct readonly
: proto::callable {
typedef const T& result_type;
};
template<typename T>
struct readwrite
: proto::callable {
typedef T& result_type;
};
template
struct argtype
: proto::or_<
proto::when, readwrite<T>()>
, proto::otherwise
{};
namespace boost { namespace proto {
template<class T> struct is_callable< readonly<T> > : mpl::true_ {};
template<class T> struct is_callable< readwrite<T> > : mpl::true_ {};
} }
Now, given an expression type E, I can say "typename
boost::result_of(const E &)>::type" and it will be
either "T0 &" or "const T0 &" depending on how _1 appears in the
expression E. Using this, I tried to write an expression wrapper with
operator() overloaded as follows :
template<typename T0>
void operator()(typename boost::result_of(const Expr
&)>::type arg0) const
{
cout << "arg0 " << arg0 << "\n";
}
But the compiler fails to find a match with this overloaded version
when I write, say, (_1)(10). Is it some fundamental C++ restriction
that causes this, or am I missing something? I will be grateful for
any advice. I am attaching the complete source code (fails to
compile).
--
Manjunath
http://nonchalantlytyped.net/blog/musings/