Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2008-03-21 12:05:35

Dean Michael Berris wrote:
> On Fri, Mar 21, 2008 at 9:17 AM, Eric Niebler <eric_at_[hidden]> wrote:
>> Larry Evans wrote:
>>> However, I'd imagine some people would want
>>> this restricted to just two elements, which could be
>>> done with something like:
>> <snip>
>>> And now, if size<Args>::value is
>>> restricted to the Arity in
>>> tag_arity<shift_right,Arity> then it
>>> would be restricted to 2.
>> Users may very well want to restrict tag::plus to arity 2 *in their
>> domain*, but they shouldn't be foisting that decision on other consumers
>> of Proto. The best way to ensure that expressions have the arity you
>> expect is to encode that in the grammar for your domain, and check it
>> with proto::matches.
> I'm nowhere near being an expert, but how would a BOOST_STATIC_ASSERT
> fit in ensuring that Args has the correct arity provided in the

What do you mean by "correct" here?

> construction of expr<>? Would there be a way to statically assert that
> 'Args' has arity 'Arity' from within Proto? Or would that be too much

Oh, Arity is the size of Args by default. expr<> is defined like:

   struct expr<Tag, Args, long Arity = Args::size>

Nowhere does Proto enforce that Arity really *is* Args::size, though.

> compile time trouble on top of all the compile time burdens
> Proto+Fusion+MPL already bring?

I don't think a static assert would be very expensive, but I also don't
think it would add much safety. In fact, it would force me to remove an
optimization in matches.hpp, where I fudge the Arity parameter to save a
few template instantiations.

Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at