This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR 90409 Deque fiil/copy/move/copy_backward/move_backward/equal overloads


On 01/08/19 13:52 +0100, Jonathan Wakely wrote:
On 01/08/19 13:31 +0200, Daniel Krügler wrote:
Am Do., 1. Aug. 2019 um 13:01 Uhr schrieb Jonathan Wakely <jwakely@redhat.com>:

On 01/08/19 12:36 +0200, Daniel Krügler wrote:
Am Do., 1. Aug. 2019 um 11:57 Uhr schrieb Jonathan Wakely <jwakely@redhat.com>:

More comments inline below ...
[..]

>François
>
>On 6/19/19 7:32 PM, François Dumont wrote:
>>I wanted to implement Debug overloads for those already existing
>>overloads but then realized that those algos could be generalized.
>>This way we will benefit from the memmove replacement when operating
>>with C array or std::array or std::vector iterators.
>>
>>I might do the same for lexicographical_compare one day.
>>
>>The ChangeLog below is quite huge so I attached it. I wonder if I
>>could use deque::iterator and deque::const_iterator in place of the
>>_Deque_iterator<> to reduce it ?
>>
>>Tested under Linux x86_64 normal and debug modes, ok to commit ?
>>
>>François
>>
>

>diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc
>index 3f77b4f079c..9db869fb666 100644
>--- a/libstdc++-v3/include/bits/deque.tcc
>+++ b/libstdc++-v3/include/bits/deque.tcc
>@@ -967,155 +967,507 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
>       this->_M_impl._M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
>     }
>
[..]

And anyway, isn't _Deque_iterator<T, T&, T*>::_Self just the same type as
_Deque_iterator<T, T&, T*> ? It should be something like:

      typedef typename _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> _Iter;

>+  template<typename _II, typename _Tp>
>+    typename enable_if<
>+      is_same<typename std::iterator_traits<_II>::iterator_category,
>+            std::random_access_iterator_tag>::value,

Use is_base_of<random_access_iterator_tag, ...::iterator_category> so
it works for types derived from random_access_iterator_tag too.

Interesting. Traditional type tag dispatching approaches (as function
parameters) do have more in a manner that would be equivalent to an
implicit conversion (Being used as "by-value-parameters"), so I'm
wondering whether this should not instead refer to is_convertible? I
also found examples where this trait is currently used in <stl_algo.h>
such as

     static_assert(
     __or_<is_convertible<__pop_cat, forward_iterator_tag>,
       is_convertible<__samp_cat, random_access_iterator_tag>>::value,
     "output range must use a RandomAccessIterator when input range"
     " does not meet the ForwardIterator requirements");

Should possibly this trait be preferred?

Hmm, I don't know why I did it that way in sample.

The standard requires derivation in a couple of places today, see
[reverse.iterator] bullet 2.1 and [move.iterator] bullet 1.1 which use
DerivedFrom<random_access_iterator_tag> to check whether the base
iterator is random access or not.

If you want to mimic DerivedFrom you also need to include
is_convertible in some way, because is_base_of does not care about
access.

Ah yes, that's probably why I used is_convertible :-)

Maybe introduce __is_derived_from?

Whatever we do, we should make it work for C++98 too, as that's needed
for François's patch. I wonder if it's good enough to just check if
iterator_traits<I>::iterator_category* converts to
random_access_iterator_tag*.

So rather than a generic is_derived_from, just a check for
is_random_access, as that's all we need here.

I already added a C++11-and-later version of that to <numeric>, but
forgot to check that the base is public and unambiguous:

 template<typename _It, typename _Traits = iterator_traits<_It>,
          typename _Cat = typename _Traits::iterator_category>
   using __is_random_access_iter
     = is_base_of<random_access_iterator_tag, _Cat>;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]