[proto] macro for wrapping expressions

What about introducing a macro: #define BOOST_PROTO_WRAP(DOMAIN,EXPRESSION) \ namespace boost { namespace proto { \ template<typename E> \ struct generate<DOMAIN, E> { \ typedef EXPRESSION<E> type; \ static type make (E const& expr) { \ return type (expr); \ } \ }; \ } } as far as I can tell one does never need something different from the above boilerplate code. (otherwise I'd like to see examples, for my own education) Not a big deal, I know, but looks nicer (and sound nicer in the docs as well, I think). Have fun in Colorado! Maurizio

Maurizio Vitale wrote:
What about introducing a macro:
#define BOOST_PROTO_WRAP(DOMAIN,EXPRESSION) \ namespace boost { namespace proto { \ template<typename E> \ struct generate<DOMAIN, E> { \ typedef EXPRESSION<E> type; \ static type make (E const& expr) { \ return type (expr); \ } \ }; \ } }
as far as I can tell one does never need something different from the above boilerplate code. (otherwise I'd like to see examples, for my own education)
Not a big deal, I know, but looks nicer (and sound nicer in the docs as well, I think).
I agree, this part of proto isn't as nice as it could be. I've considered making the expression generator a template parameter to the proto::domain, something like: struct my_domain : proto::domain< struct my_grammar, struct my_generator > {}; This way, you wouldn't have to open proto's namespace to specialize proto::generate. I haven't thought too hard about it, though. I do know that I would like to avoid macros in proto's interface as much as possible.
Have fun in Colorado!
Workin' on it! :-) -- Eric Niebler Boost Consulting www.boost-consulting.com

Eric Niebler <eric@boost-consulting.com> writes:
Maurizio Vitale wrote:
What about introducing a macro:
#define BOOST_PROTO_WRAP(DOMAIN,EXPRESSION) \ [cut]
I agree, this part of proto isn't as nice as it could be. I've considered making the expression generator a template parameter to the proto::domain, something like:
struct my_domain : proto::domain< struct my_grammar, struct my_generator > {};
This way, you wouldn't have to open proto's namespace to specialize proto::generate. I haven't thought too hard about it, though. I do know that I would like to avoid macros in proto's interface as much as possible.
Instead of the macro I was thinking about defining the generator inside my_domain. If the code is really always the same, it is not even necessary to define the complete generator, just the expression to wrap around proto expressions. I think where the wrapper is used, my_context is available. If this is doable it would encapsulate the wrapper inside the domain, which is where it belongs. Unless there're legitimate uses for the same domain wrapped differently. But then there's too much of proto I don't know, and I just proposed the macro... Regards, Maurizio

Maurizio Vitale wrote:
Eric Niebler <eric@boost-consulting.com> writes:
What about introducing a macro:
#define BOOST_PROTO_WRAP(DOMAIN,EXPRESSION) \ [cut] I agree, this part of proto isn't as nice as it could be. I've considered making the expression generator a template parameter to the
Maurizio Vitale wrote: proto::domain, something like:
struct my_domain : proto::domain< struct my_grammar, struct my_generator > {};
This way, you wouldn't have to open proto's namespace to specialize proto::generate. I haven't thought too hard about it, though. I do know that I would like to avoid macros in proto's interface as much as possible.
Instead of the macro I was thinking about defining the generator inside my_domain. If the code is really always the same, it is not even necessary to define the complete generator, just the expression to wrap around proto expressions. I think where the wrapper is used, my_context is available.
If this is doable it would encapsulate the wrapper inside the domain, which is where it belongs.
This is now implemented. Proto::generate<> is gone. You now specify the expression generator as a template parameter to proto::domain. NOTE: the generator parameter comes first! The (optional) grammar parameter is now second. Also, there is a helper for adapting an expression wrapper to a generator. Given some expression wrapper: struct mydomain; template<typename Expr> struct myexpr : proto::extends<Expr, myexpr<Expr>, mydomain> ... You can specify the generator with: struct mydomain : proto::domain< proto::generator<myexpr> > {}; This change should loudly break any existing code that uses generators. Sorry for that. -- Eric Niebler Boost Consulting www.boost-consulting.com
participants (2)
-
Eric Niebler
-
Maurizio Vitale