|
Boost : |
Subject: Re: [boost] Is Boost.Range broken?
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-11-26 09:51:15
On Wed, Nov 26, 2008 at 09:15, Thorsten Ottosen
<thorsten.ottosen_at_[hidden]> wrote:
> Giovanni Piero Deretta skrev:
>>
>> On Wed, Nov 26, 2008 at 4:46 AM, Scott McMurray <me22.ca+boost_at_[hidden]>
>> wrote:
>>>
>>> [...]
>>
>> [ i think you want to change all node_iter to nonsingular_default ]
>>
Yes, dumb copy-paste mistake on my part.
>>
>> I do not think you can even copy a singular iterator (and at least
>> libstdc++ will assert in debug mode),
>
> Right. you can't even copy a singular iterator (not portably, at least).
>
Another good point.
I think this works, as the iterator_adaptor's copy ctr is never called:
template <class Iter>
class nonsingular_default
: public boost::iterator_adaptor<
nonsingular_default<Value> // Derived
, Iter // Base
>
{
private:
bool is_default_constructed;
public:
nonsingular_default()
: nonsingular_default::iterator_adaptor_(),
is_default_constructed(true) {}
nonsingular_default(Iter const &i)
: nonsingular_default::iterator_adaptor_(i),
is_default_constructed(false) {}
nonsingular_default(nonsingular_default const &i) {
*this = i;
}
nonsingular_default &operator=(nonsingular_default const &i) {
is_default_constructed = i.is_default_constructed;
if (!is_default_constructed) {
base_reference() = i.base();
}
}
private:
friend class boost::iterator_core_access;
bool equal(nonsingular_default const &i) {
if (is_default_constructed && i.is_default_constructed) {
return true;
}
if (!is_default_constructed && !i.is_default_constructed) {
return base == i.base();
}
return false;
}
};
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk