Boost logo

Boost :

Subject: Re: [boost] [Proto] Computing type in expression
From: Eric Niebler (eric_at_[hidden])
Date: 2010-06-15 09:32:28

On 6/15/2010 9:17 AM, joel falcou wrote:
> Eric Niebler wrote:
>> template<class Expr> struct wrap
>> : proto::extends<Expr, wrap<Expr> >
>> {
>> // Expr is complete here
>> // wrap is not
>> typedef typename some_fun<wrap>::type value_type; // NO
>> typedef typename some_fun<Expr>::type value_type; // YES
>> };
>> Does that help?
> Makes perfect sense, feel a bit stupid now :E
> I will try to get that working out ;)
> Thanks for the head up

Don't feel stupid; there are contexts in which you actually *can* use
wrap in type computations within wrap itself, so it's easy to get confused.

 template<class Expr>
 struct wrap
   : proto::extends<Expr, wrap<Expr> >
   template<struct Sig>
   struct result
     typedef typename some_fun<wrap>::type type; //OK!

The difference is that by the time result gets instantiated somewhere
else in your program, wrap will be complete. This will work fine until
you try to instantiate result from within wrap itself (e.g. to compute
the return type of a nullary operator() overload). Then it blows up with
very mysterious errors. It's tricky.

Eric Niebler
BoostPro Computing

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