|
Boost Users : |
Subject: [Boost-users] [proto] transform for a templated proto::terminal type
From: Manjunath Kudlur (keveman_at_[hidden])
Date: 2010-02-05 21:35:31
Hello,
I have some proto::terminal's as follows :
template<typename T>
struct Var {
unsigned int id;
};
typedef proto::terminal<Var<int> >::type int32_;
typedef proto::terminal<Var<float> >::type float_;
typedef proto::terminal<Var<double> >::type double_;
I can write a callable transform, with templated operator() functions
to handle each Var<> type as follows :
struct _var_tostr :
proto::callable {
typedef std::string result_type;
template<typename T>
result_type operator()(variables::Var<T> const &v) const {
std::stringstream sout;
sout << "S" << v.id;
return sout.str();
}
template<typename T>
result_type operator()(variables::VecVar<T> const &v) const {
std::stringstream sout;
sout << "V" << v.id;
return sout.str();
}
};
To activate the transform, I end up writing one rule for each Var<>
type as follows :
struct var_tostr :
proto::or_<
proto::when<proto::terminal<variables::Var<int> >,
_var_tostr(proto::_value)>
,proto::when<proto::terminal<variables::Var<float> >,
_var_tostr(proto::_value)>
,proto::when<proto::terminal<variables::Var<double> >,
_var_tostr(proto::_value)>
> {
};
This gets cumbersome when I have more Var<> types. Is there a way to
not list each Var<> type in the grammar? That is, I want to match any
Var<T> and just call the _var_tostr(proto::_value) transform. How can
I accomplish this?
Thanks,
Manjunath
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net