Commit b091b8dc by Jonathan Wakely Committed by Jonathan Wakely

PR78273 fix count to work with partitioning function

	PR libstdc++/78273
	* include/bits/stl_map.h (map::count<_Kt>(const _Kt&)): Don't assume
	the heterogeneous comparison can only find one match.
	* include/bits/stl_set.h (set::count<_Kt>(const _Kt&)): Likewise.
	* testsuite/23_containers/map/operations/2.cc: Test count works with
	comparison function that just partitions rather than sorting.
	* testsuite/23_containers/set/operations/2.cc: Likewise.

From-SVN: r244317
parent a92ffb3e
2017-01-11 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/78273
* include/bits/stl_map.h (map::count<_Kt>(const _Kt&)): Don't assume
the heterogeneous comparison can only find one match.
* include/bits/stl_set.h (set::count<_Kt>(const _Kt&)): Likewise.
* testsuite/23_containers/map/operations/2.cc: Test count works with
comparison function that just partitions rather than sorting.
* testsuite/23_containers/set/operations/2.cc: Likewise.
2017-01-11 Ville Voutilainen <ville.voutilainen@gmail.com> 2017-01-11 Ville Voutilainen <ville.voutilainen@gmail.com>
Reduce the size of variant, it doesn't need an index of Reduce the size of variant, it doesn't need an index of
......
...@@ -1194,7 +1194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1194,7 +1194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
template<typename _Kt> template<typename _Kt>
auto auto
count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
{ return _M_t._M_find_tr(__x) == _M_t.end() ? 0 : 1; } { return _M_t._M_count_tr(__x); }
#endif #endif
//@} //@}
......
...@@ -739,7 +739,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -739,7 +739,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
auto auto
count(const _Kt& __x) const count(const _Kt& __x) const
-> decltype(_M_t._M_count_tr(__x)) -> decltype(_M_t._M_count_tr(__x))
{ return _M_t._M_find_tr(__x) == _M_t.end() ? 0 : 1; } { return _M_t._M_count_tr(__x); }
#endif #endif
//@} //@}
......
...@@ -133,6 +133,27 @@ test05() ...@@ -133,6 +133,27 @@ test05()
VERIFY( Cmp::count == 0); VERIFY( Cmp::count == 0);
} }
void
test06()
{
// PR libstdc++/78273
struct C {
bool operator()(int l, int r) const { return l < r; }
struct Partition { };
bool operator()(int l, Partition) const { return l < 2; }
bool operator()(Partition, int r) const { return 4 < r; }
using is_transparent = void;
};
std::map<int, int, C> m{ {1,0}, {2,0}, {3,0}, {4, 0}, {5, 0} };
auto n = m.count(C::Partition{});
VERIFY( n == 3 );
}
int int
main() main()
...@@ -142,4 +163,5 @@ main() ...@@ -142,4 +163,5 @@ main()
test03(); test03();
test04(); test04();
test05(); test05();
test06();
} }
...@@ -150,6 +150,28 @@ test06() ...@@ -150,6 +150,28 @@ test06()
s.find(i); s.find(i);
} }
void
test07()
{
// PR libstdc++/78273
struct C {
bool operator()(int l, int r) const { return l < r; }
struct Partition { };
bool operator()(int l, Partition) const { return l < 2; }
bool operator()(Partition, int r) const { return 4 < r; }
using is_transparent = void;
};
std::set<int, C> s{ 1, 2, 3, 4, 5 };
auto n = s.count(C::Partition{});
VERIFY( n == 3 );
}
int int
main() main()
{ {
...@@ -159,4 +181,5 @@ main() ...@@ -159,4 +181,5 @@ main()
test04(); test04();
test05(); test05();
test06(); test06();
test07();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment