public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "Daniel Krügler" <daniel.kruegler@gmail.com>
Cc: "François Dumont" <frs.dumont@gmail.com>,
	"libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: PR 90409 Deque fiil/copy/move/copy_backward/move_backward/equal overloads
Date: Thu, 01 Aug 2019 12:53:00 -0000	[thread overview]
Message-ID: <20190801125338.GR9487@redhat.com> (raw)
In-Reply-To: <20190801125224.GQ9487@redhat.com>

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>;

  reply	other threads:[~2019-08-01 12:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-19 17:32 François Dumont
2019-06-20  8:38 ` Morwenn Ed
2019-06-21  4:43   ` François Dumont
2019-07-16 17:20 ` François Dumont
2019-07-26  9:13 ` PR 90409 " François Dumont
2019-08-01  9:57   ` Jonathan Wakely
2019-08-01 10:36     ` Daniel Krügler
2019-08-01 11:01       ` Jonathan Wakely
2019-08-01 11:31         ` Daniel Krügler
2019-08-01 12:52           ` Jonathan Wakely
2019-08-01 12:53             ` Jonathan Wakely [this message]
2019-08-21 21:18               ` François Dumont
2019-08-26 20:31                 ` François Dumont

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190801125338.GR9487@redhat.com \
    --to=jwakely@redhat.com \
    --cc=daniel.kruegler@gmail.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).