public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/64903] New: is_partitioned should not apply a predicate more than (last - first) times
@ 2015-02-02 16:06 kariya_mitsuru at hotmail dot com
2015-02-02 16:24 ` [Bug libstdc++/64903] " redi at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-02-02 16:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64903
Bug ID: 64903
Summary: is_partitioned should not apply a predicate more than
(last - first) times
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: kariya_mitsuru at hotmail dot com
Created attachment 34645
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34645&action=edit
g++ -v
Please see the sample code below.
================================= sample code =================================
#include <iostream>
#include <algorithm>
int main()
{
int v[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10 };
int c = 0;
std::cout << std::boolalpha
<< std::is_partitioned(v, v + 10, [&c](int x) { return ++c, (x & 1) !=
0; })
<< std::endl;
std::cout << c << " times" << std::endl;
}
================================= sample code =================================
================================= output =================================
true
11 times
================================= output =================================
cf. http://melpon.org/wandbox/permlink/OHXgHtbgmm4Ak8pJ
The C++11 standard 25.3.13[alg.partitions]/p.3 says, "At most last - first
applications of pred."
So the sample code above should output
================================= output =================================
true
10 times
================================= output =================================
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug libstdc++/64903] is_partitioned should not apply a predicate more than (last - first) times
2015-02-02 16:06 [Bug libstdc++/64903] New: is_partitioned should not apply a predicate more than (last - first) times kariya_mitsuru at hotmail dot com
@ 2015-02-02 16:24 ` redi at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-02 16:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64903
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-02-02
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I notice that libc++ has the same bug.
I think the problem is that we end up testing the partition point twice. Here's
a completely untested patch that avoids that:
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -583,6 +583,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Predicate __pred)
{
__first = std::find_if_not(__first, __last, __pred);
+ if (__first == __last)
+ return true;
+ std::advance(__first, 1);
return std::none_of(__first, __last, __pred);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-02 16:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-02 16:06 [Bug libstdc++/64903] New: is_partitioned should not apply a predicate more than (last - first) times kariya_mitsuru at hotmail dot com
2015-02-02 16:24 ` [Bug libstdc++/64903] " 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).