Boost logo

Proto :

Subject: Re: [proto] problems with proto::matches
From: Eric Niebler (eric_at_[hidden])
Date: 2012-12-13 12:44:10


On 12/13/2012 4:51 AM, Thomas Heller wrote:
> Hi,
>
> I recently discovered a behavior which i find quite odd:
> proto::matches<Expression, Grammar>::type fails when Expression is not a
> proto expression. I would have expected that it just returns false in
> this case. What am I missing. Patch is attached for what i think would
> be a better behavior of that meta function.

Hi Thomas,

Thanks for the patch. Pros and cons to this. Pro: it works in more
situations, including yours. (Could you tell me a bit about your
situation?) Also, the implementation is dead simple and free of extra
TMP overhead.

Cons: Someone might expect a non-Proto type to be treated as a terminal
of that type and be surprised at getting a false where s/he expected
true (a fair assumption since Proto treats non-expressions as terminals
elsewhere; e.g., in its operator overloads). It slightly complicates the
specification of matches. It is potentially breaking in that it changes
the template arity of proto::matches. (Consider what happens if someone
is doing mpl::quote2<proto::matches>.)

I'm inclined to say this is not a bug and that it's a prerequisite of
matches that Expression is a proto expression. If you want to use it
with types that aren't expressions, you can already do that:

  template<class MaybeExpr, class Grammar>
  struct maybe_matches
    : mpl::if_< proto::is_expr<MaybeExpr>
              , proto::matches<MaybeExpr, Grammar>
              , mpl::false_
>::type
  {};

Would the above work for you? I realize that's more expensive than what
you're doing now. :-(

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Proto list run by eric at boostpro.com