Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-10-27 17:06:38


AMDG

Ion Gaztañaga <igaztanaga <at> gmail.com> writes:

> You are right. I'm returning the address of a temporary! I think
> conceptually the iterator is wrong. I should return char & for
> operator*() instead of char *. char *should be returned by operator->.
>
> However this makes the code uglier:
>
> multiallocation_iterator it = ...
>
> for(...)
> //placement new
> new(&*it++) T();
>
> instead of
>
> for(...)
> //placement new
> new(*it++) T();
>
> If I want basic_multiallocation_iterator to be a well-formed iterator I
> need to define operator->() so I think I'll need to change the interface
> of this class (I doubt anyone is using it). Give me some time to change
> it and pass the tests again.

It isn't /necessary/.

template<class T, class pointer>
struct arrow_proxy {
    arrow_proxy(const T& t) : impl(t) {}
    pointer operator->() const { return(&impl); }
    T impl;
}

arrow_proxy<value_type, pointer> operator->() {
    return(arrow_proxy<value_type, pointer>(**this));
}

In Christ,
Steven Watanabe


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