Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2007-05-12 18:15:41


on Sat May 12 2007, Andrey Semashev <andysem-AT-mail.ru> wrote:

> Hello David,

<please avoid overquoting>

> I apologize for returning to this, but as I'm reading the docs and
> looking at my use cases I have before me I don't see how would I elide
> is_const_iterator when using iterator_adaptor. Suppose this:
>
> template< typename ValueT >
> class MyList
> {
> public:
> typedef ValueT value_type;
>
> // etc. all other common typedefs except iterators
>
> private:
> struct MyNode
> {
> ValueT value;
> int m_SomeOtherData;
> };
> typedef std::list< MyNode > underlying_container;
>
> template< typename >
> class MyIterator;
>
> public:
> typedef MyIterator<
> typename underlying_container::iterator
> > iterator;
>
> typedef MyIterator<
> typename underlying_container::const_iterator
> > const_iterator;
>
> private:
> template< typename ItT >
> class MyIterator :
> public iterator_adaptor<
> MyIterator< ItT >,
> ItT,
> value_type, // I have to substitute value type

No, just leave it out. The default works.

> use_default, // Category fits well
> ??? // What should I write for reference type?
> // I've provided value type, so value_type&
> // is not valid when ItT is const_iterator

Just leave it out. The default works.

> >
> {
> typedef typename iterator_adaptor<
> ...
> >::reference reference;
>
> reference dereference()
> {
> return this->base()->value;
> }
> };
> };
>
> So, once again I have to detect ItT constness and form up the correct
> reference type for the iterator_adaptor. Am I missing something?

...unless I'm missing something.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
Don't Miss BoostCon 2007! ==> http://www.boostcon.com

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