Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-03-01 08:39:57


On 02/28/2005 06:35 PM, David Abrahams wrote:
> Larry Evans <cppljevans_at_[hidden]> writes:
>
>>On 02/28/2005 10:01 AM, David Abrahams wrote:
[snip]
>>>You're folding some kind of cons cell, right? Don't you want to
>>>implement begin and end on that?
>>> template <class A, class B>
>>> struct begin<inherit<A,B> >
>>> {
>>> ...
>>> };
>>>or something?
>>
>>Yes. But how do I know what A or B is.
>
> ??
>
> At the point of ... the compiler knows what they are

So, I tried:
//{--------- cut-here --------
template <
    template<typename,typename>class ForwardOpTmpl
  , typename LeftArg
  , typename RightArg
>
struct begin < ForwardOpTmpl<LeftArg,RightArg> >
{
     typedef ForwardOpTmpl<LeftArg,RightArg> type;
};

template <
   template<typename,typename>class ForwardOpTmpl
, typename LeftArg
, typename RightArg
>
struct next < ForwardOpTmpl<LeftArg,RightArg> >
{
     typedef RightArg type;
};
//}--------- cut-here --------
But intel-linux said next was ambiguous. Also, the above
code assumes the last arg to fold was:

   ForwardOpTmpl<arg<2>,arg<1> >

I was hoping to be more general, but maybe just for my test,
it would be OK.

>
>>It has to be the result
>>of size<Sequence>-1 applications of ForwardOp.
>
>
> Do you mean that you want to restrict the partial specialization
> matching to only match your tuple types? You don't have to use
> inherit directly, you know; you could just derive your own my_inherit
> class from it and match that in the partial specialization. If you
> only use my_inherit to build these tuples, you're home free.
>
Replacing ForwardOpTmpl with my_inherit, defined as:

template< typename Left, typename Right>
struct my_inherit: inherit2<Left,Right>
{
     typedef my_inherit type;
};

still got the ambiguous error message with intel-linux. gcc gave some
other error message.

Even if the above did, work, I'd need an end specialization,
and that would involve knowing the 2nd arg to fold; hence,
the specialization would have to be:

template<typename Sequence, typename Start, typename ForwardOp>
struct end<fold<Sequence,Start,ForwardOp>::type>
{
...
};

which is doomed to fail (AFAICT) because of the non-deduced
context.

Or am I missing something again?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk