|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-04-11 00:41:49
Ion Gaztañaga <igaztanaga_at_[hidden]> writes:
> Sorry, I really wanted to say "random access traversal" instead of
> random access iterator. Taking a snippet of the proposed implementation:
>
> template <class T, class Difference = std::ptrdiff_t>
> class range_from_ref_iterator
> : public boost::iterator_facade
> < range_from_ref_iterator<T, Difference>
> , T
> , boost::random_access_traversal_tag
> , T &
> , Difference>
>
>
> Correct me if I'm wrong but what I want is to simulate a source of N
> identical objects without modifying them, so I think this is a Readable
> Iterator and a Random Access Traversal Iterator.
Yes, but unless you take special measures, the iterator library will
notice that you're using random access traversal and your reference
type is a real reference, and it will make
iterator_traits<range_from_ref_iterator<...> >::iterator_category be
random_access_iterator_tag.
IIUC, that would be a nonconforming iterator.
24.1.3 says:
If a and b are both dereferenceable, then a == b if and only if *a and
*b are the same object.
I don't think your iterators meet taht criterion.
> I would now propose something like:
>
> template <class T, class Difference = std::ptrdiff_t>
> class repeat_read_iterator
> : public boost::iterator_facade
> < repeat_read_iterator<T, Difference>
> , const T
> , boost::random_access_traversal_tag
> , const T &
> , Difference>
>
> so dereferencing "repeat_read_iterator<T>" would return const T & with
> random_access_traversal capability to be able move fast inside that
> "virtual read-only array". Am I missing something?
Only that the library will assign the wrong category unless you do
something to prevent it.
> Do you see this read only repeated sequence simulation useful to
> include it the iterator library?
Sure. But useful enough? That I do not know.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk