reference type of output_iterator_wrapper

Howard Hinnant hhinnant@apple.com
Mon Apr 17 19:59:00 GMT 2006


On Apr 17, 2006, at 9:55 AM, Doug Gregor wrote:

>   template<class T>
>   struct output_iterator_wrapper: public std::iterator
>   <std::output_iterator_tag, T, ptrdiff_t, T*, T&>
>   {
>     // ...
>
>     WritableObject<T>
>     operator*() const
>     {
>       ITERATOR_VERIFY(ptr < SharedInfo->last);
>       ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo- 
> >first] == false);
>       return WritableObject<T>(ptr, SharedInfo);
>     }
>
>     // ...
> };
>
> output_iterator_wrapper<T>::reference is defined to be T&, whereas  
> operator* returns WritableObject<T>. Sure, you won't find anywhere  
> in the standard that explicitly says that the "reference" type  
> needs to be the same as the return type of operator*, but it's  
> implied by the uses of "reference" (e.g., in reverse_iterator).  
> Anyway, I doubt the current output_iterator_wrapper would pass a  
> concept checker, and it fails in ConceptGCC.
>
> I suggest changing the last argument of the std::iterator base to  
> WritableObject<T>. Patch attached.

Fwiw I suggested the standard do something like this in Berlin and  
got met with pretty strong opposition (give a non-void  
iterator_traits to output iterators).  The standard currently says  
that value_type and difference_type should be void for output  
iterators (24.3.1/1).  I think it's a bad rule, and apparently I'm  
not alone.  But there's an up hill battle in the LWG here.  Packaging  
it with concepts might help.

-Howard



More information about the Libstdc++ mailing list