public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Reimplement __gnu_cxx::__ops operators
Date: Thu, 7 Dec 2023 13:41:58 +0000	[thread overview]
Message-ID: <CACb0b4kkxEEmoYk9dFFGk3t-TBdH_o5HiR5i9YuAbqOD8psYjw@mail.gmail.com> (raw)
In-Reply-To: <9c9d0f26-4ca9-4c1b-86fa-63bc65d21ecf@gmail.com>

On Wed, 6 Dec 2023 at 20:55, François Dumont <frs.dumont@gmail.com> wrote:
>
> I think I still got no feedback about this cleanup proposal.

Can you remind me why we have all those different functions in
predefined_ops.h in the first place? I think it was to avoid having
two versions of every algorithm, one that does *l < *r and one that
does pred(*l, *r), right?

One property of the current code is that _Iter_less_iter will compare
exactly *lhs < *rhs and so works even with this type, where its
operator< only accepts non-const arguments:

struct X { bool operator<(X&); };

Doesn't your simplification break that, because the _Less function
only accepts const references now?

Maybe another way to remove the number of types in predefined_ops.h
would be to compose functions from projections. So instead of
_Iter_less_iter and _Iter_less_val etc. we have:

template<typename LProj, typename RProj>
struct _Less
{
  template<typename T, typename U>
    bool operator()(T& l, U& r) const
    { return LProj()(l) < RProj()(r); }
};

And a set of projections:

struct _Proj_deref {
  template<typename T>
    decltype(auto) operator()(T& t) const
    { return *t; }
};
struct _Proj_identity {
  template<typename T>
    T& operator()(T& t) const
    { return t; }
};

Then:

using _Iter_less_iter =_Less<_Proj_deref, _Proj_deref>;
using _Iter_less_val = _Less<_Proj_deref, _Proj_identity>;

The problem here is the use of decltype(auto) which isn't valid in
C++98. If we didn't have to support C++98 then we could just use
forwarding refs in_Less::operator()(T&&, U&&) and use perfect
forwarding everywhere. But we can't.


>
> Here is a new version.
>
> François
>
> On 15/06/2023 07:07, François Dumont wrote:
> > I think we all agree that __gnu_cxx::__ops needed to be reimplemented,
> > here it is.
> >
> > Note that I kept the usage of std::ref in <string>, <vector> and <deque>.
> >
> >     libstdc++: Reimplement __gnu_cxx::__ops operators
> >
> >     Replace functors using iterators as input to adopt functors that
> >     are matching the same Standard expectations as the ones imposed on
> >     predicates used in predicates-aware algos. Doing so we need far less
> >     functors. It impose that iterators are dereference at algo level and
> >     not in the functors anymore.
> >
> >     libstdc++-v3/ChangeLog:
> >
> >             * include/std/functional (_Not_fn): Move to...
> >             * include/bits/predefined_ops.h: ...here, and expose a
> > version
> >             in pre-C++14 mode.
> >             (__not_fn): New, use latter.
> >             (_Iter_less_iter, _Iter_less_val, _Val_less_iter,
> > _Iter_equal_to_iter)
> >             (_Iter_equal_to_val, _Iter_comp_iter, _Iter_comp_val,
> > _Val_comp_iter)
> >             (_Iter_equals_val, _Iter_equals_iter, _Iter_pred,
> > _Iter_comp_val)
> >             (_Iter_comp_to_val, _Iter_comp_to_iter, _Iter_negate):
> > Remove.
> >             (__iter_less_iter, __iter_less_val, __iter_comp_val,
> > __val_less_iter)
> >             (__val_comp_iter, __iter_equal_to_iter,
> > __iter_equal_to_val, __iter_comp_iter)
> >             (__val_comp_iter, __iter_equals_val, __iter_comp_iter,
> > __pred_iter): Remove.
> >             (_Less, _Equal_to, _Equal_to_val, _Comp_val): New.
> >             (__less, __equal_to, __comp_val): New.
> >             * include/bits/stl_algo.h: Adapt all algos to use new
> > __gnu_cxx::__ops operators.
> >             When possible use std::move to pass predicates between
> > routines.
> >             * include/bits/stl_algobase.h: Likewise.
> >             * include/bits/stl_heap.h: Likewise.
> >             * include/std/deque: Cleanup usage of __gnu_cxx::__ops
> > operators.
> >             * include/std/string: Likewise.
> >             * include/std/vector: Likewise.
> >
> > Tested under Linux x86_64 normal and _GLIBCXX_DEBUG modes.
> >
> > Ok to commit ?
> >
> > François
> >


  reply	other threads:[~2023-12-07 13:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15  5:07 François Dumont
2023-12-06 20:54 ` François Dumont
2023-12-07 13:41   ` Jonathan Wakely [this message]
2023-12-07 14:04     ` Jonathan Wakely
2024-04-04 17:24       ` François Dumont
2023-12-09 13:04     ` 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=CACb0b4kkxEEmoYk9dFFGk3t-TBdH_o5HiR5i9YuAbqOD8psYjw@mail.gmail.com \
    --to=jwakely@redhat.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).