PR libstdc++/68222 Hide safe iterator operators
Jonathan Wakely
jwakely@redhat.com
Tue Aug 7 22:41:00 GMT 2018
On 07/08/18 14:47 +0100, Jonathan Wakely wrote:
>On 02/08/18 22:16 +0200, François Dumont wrote:
>>Hi
>>
>>Â Â Â Here is a patch to avoid definition of invalid operators on the
>>Debug mode safe iterator type depending on its category.
>>
>>Â Â Â Even if it is limited to the Debug mode code I would like to
>>have a feedback before committing. Especially on the following
>>points:
>>
>>- _Safe_tagged_iterator: Is the name ok ?
>
>Hmm, maybe "strict" instead of tagged?
>
>But do we need a new name? Can we just change _Safe_iterator instead
>of adding a new type?
>
>Where is _Safe_iterator still used? Just local iterators in unordered
>containers? Is it OK to remove most of the functions that used to
>support it? (__niter_base etc).
>
>Could we add a new type for the local iterators, and just change
>_Safe_iterator directly so it doesn't expose unsupported operations?
>
>That would make the patch *much* smaller, as you wouldn't need to
>change all the uses of _Safe_iterator.
>
>
>Another approach would be to use mixins to expose the operations:
>
>template<typename _Iter, typename _Cat>
>struct _Safe_iterator_mixin<_Iter, _Cat>
>{
> typename iterator_traits<_Iter>::reference
> operator*()
> { return static_cast<_Iter*>(this)->_M_deref(); }
>};
>
>template<typename _Iter, typename _Cat>
>struct _Safe_iterator_mixin<_Iter, forward_iterator_tag>
>{
> _Iter& operator++()
> { return static_cast<_Iter*>(this)->_M_preinc(); }
> _Iter operator++(int)
> { return static_cast<_Iter*>(this)->_M_postinc(); }
>};
>
>template<typename _Iter, typename _Cat>
>struct _Safe_iterator_mixin<_Iter, bidirectional_iterator_tag>
>{
> _Iter& operator--()
> { return static_cast<_Iter*>(this)->_M_predec(); }
> _Iter operator--(int)
> { return static_cast<_Iter*>(this)->_M_postdec(); }
>};
>
>etc.
>
>then in _Safe_iterator rename the operator functions, so operator*
>becomes _M_deref, operator++ becomes _M_preinc etc. and then derive
>from _Safe_iterator_mixin which declares the operators.
FWIW I think your proposal with partial specializations for each
iterator category is probably better than this mixins idea (although I
think it requires a lot more code to implement it).
But I would like to know if it's possible to just change
_Safe_iterator instead of introducing a new _Safe_tagged_iterator
type.
More information about the Libstdc++
mailing list