public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/108714] New: Algorithms in <algorithm> require predicates to be copyable
@ 2023-02-08  8:56 b.stanimirov at abv dot bg
  2023-02-08 11:28 ` [Bug libstdc++/108714] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: b.stanimirov at abv dot bg @ 2023-02-08  8:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108714

            Bug ID: 108714
           Summary: Algorithms in <algorithm> require predicates to be
                    copyable
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b.stanimirov at abv dot bg
  Target Milestone: ---

Simple repro:

```
#include <algorithm>
#include <vector>

struct noncopyable {
    noncopyable();
    noncopyable(const noncopyable&) = delete;
    noncopyable(noncopyable&&) noexcept = default;
    template <typename T>
    bool operator()(const T&);
};

bool all_of_vec(const std::vector<int>& vec) {
    return std::all_of(vec.begin(), vec.end(), noncopyable{});
}
```

This does not compile, because the predicate to `all_of` is not copyable. The
same error appears for all other algorithms which allow a predicate.

It does compile and work and expected with Microsoft STL and with libc++

Live demo showing compilation errors with libstdc++ and successful compilation
with libc++ and Microsoft STL: https://godbolt.org/z/xaa35G35e

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/108714] Algorithms in <algorithm> require predicates to be copyable
  2023-02-08  8:56 [Bug libstdc++/108714] New: Algorithms in <algorithm> require predicates to be copyable b.stanimirov at abv dot bg
@ 2023-02-08 11:28 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-08 11:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108714

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Not a bug, the standard is clear about this:

[Note 2 : Unless otherwise specified, algorithms that take function objects as
arguments can copy those function objects freely. If object identity is
important, a wrapper class that points to a non-copied implementation object
such as reference_wrapper<T> (22.10.6), or some equivalent solution, can be
used. — end note]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-08 11:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08  8:56 [Bug libstdc++/108714] New: Algorithms in <algorithm> require predicates to be copyable b.stanimirov at abv dot bg
2023-02-08 11:28 ` [Bug libstdc++/108714] " redi at gcc dot gnu.org

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).