Subject: Re: [proto] Held nodes by value for Fundamental types
From: Fernando Pelliccioni (fpelliccioni_at_[hidden])
Date: 2012-04-10 09:48:11
On Mon, Apr 9, 2012 at 7:00 PM, Eric Niebler <eric_at_[hidden]> wrote:
> On 4/9/2012 2:21 PM, Fernando Pelliccioni wrote:
> > Hello,
> > I'm wondering if it would be appropriate to treat the fundamental types
> > (char, short, int, double, ...) by value, by default.
> > I wrote this simple piece of code.
> > I'm not sure if I'm leaving without considering any other implication,
> > but I think it may be an improvement.
> > Please, tell me if I am wrong.
> Thanks. I thought long about whether to handle the fundamental types
> differently than user-defined types and decided against it. The
> capture-everything-by-reference-by-default model is easy to explain and
> reason about. Special cases can be handled on a per-domain basis as needed.
Thanks for your reply.
The design philosophy is unobjectionable.
> There is a way to change the capture behavior for your domain. The newly
> released version of Proto documents how to do this (although the
> functionality has been there for a few releases already).
I had read that chapter, but I thought it might be the behavior of
> In short, you'll need to define an as_child metafunction in your domain
> class my_domain
> : proto::domain< my_generator, my_grammar >
> // Here is where you define how Proto should handle
> // sub-expressions that are about to be glommed into
> // a larger expression.
> template< typename T >
> struct as_child
> typedef unspecified-Proto-expr-type result_type;
> result_type operator()( T & t ) const
> return unspecified-Proto-expr-object;
> In as_child, you'll have to do this (pseudocode):
> if (is_expr<T>)
> return T &
> else if(is_fundamental<T>)
> return proto::terminal<T>::type
> return proto::terminal<T &>::type
I implemented it by defining as_child in my domain.
> The metaprogramming is left as an exercise. :-)
... Happy metaprogramming :)
Thanks for your clarification.
Proto list run by eric at boostpro.com