Boost logo

Boost :

Subject: Re: [boost] [fusion] pop_back doesn't work on fwd sequences
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-08-12 02:49:55


On Thu, Aug 11, 2011 at 11:33 PM, Joel de Guzman
<joel_at_[hidden]>wrote:

> On 8/12/2011 2:12 PM, Jeffrey Lee Hellrung, Jr. wrote:
>
[...]

> > Okay, here are the functional differences between our implementations:
>
[...]

> > - I do *not* have default implementations of next, prior, and advance,
> > instead forcing the derived class to implement these, if desired; I
> notice
> > you require the derived class to implement a make metafunction, which I
> > guess is fine, but then shouldn't iterator_adaptor::advance::call use
> > something like Derived_::make::call, so ultimately put the iterator
>
> You are looking at a slightly older version. It's been fixed.
>

Ah, okay...as I don't actually have the trunk checked out, I just used the
online browser; I'll go ahead and check out truck.

> > construction responsibility on the derived class? If so, I'm not sure if
> > providing default implementations of next, prior, and advance is really
> all
> > that convenient...
>
> Consider a transform iterator where you want a next, prior, advance
> to do as usual, but 'override' the behavior of value_of and deref
> to do your bidding. In that common case, you do not want to bother
> with the reimplementations.
>

Yeah, after sending that I changed my mind regarding that conclusion; it is
indeed more convenient to only implement the factory "make" stuff in the
derived class once than write out the boilerplate for all of next, prior,
and advance.

> > - I also include default implementations of key_of, value_of_data, and
> > deref_data.
>
> Good! I'd welcome a merge.
>

errr...patch? It is really quite trivial (I think...):

    template< class This >
    struct key_of
        : boost::fusion::result_of::key_of< base_type >
    { };

    template< class This >
    struct value_of_data
        : boost::fusion::result_of::value_of_data< base_type >
    { };

    template< class This >
    struct deref_data
    {
        typedef typename boost::fusion::result_of::deref_data< base_type
>::type type;
        static type call(This& this_)
        { return boost::fusion::deref_data(this_.m_base); }
    };

So, as I look at this (pasted from my implementation), I now wonder: Is
there a difference between This::base_type and base_type in the above
structs? E.g., does it make a difference whether one uses key_of< base_type
> or key_of< typename This::base_type > ? (Here, base_type is a typedef for
the underlying iterator you're adapting, i.e., the Iterator_ parameter in
your implementation.)

- Jeff


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