-// Copyright (C) 2015 Free Software Foundation, Inc.
+// Copyright (C) 2015-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// { dg-options "-std=gnu++14" }
+// { dg-do run { target c++14 } }
#include <set>
#include <testsuite_hooks.h>
cit = cx.find(2L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "find returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const find returns const_iterator");
}
void
cn = cx.count(2L);
VERIFY( cn == 0 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
}
void
cit = cx.lower_bound(2L);
VERIFY( cit != cx.end() && *cit == 3 );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "lower_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const lower_bound returns const_iterator");
}
void
cit = cx.upper_bound(5L);
VERIFY( cit == cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ static_assert(std::is_same<decltype(it), test_type::iterator>::value,
+ "upper_bound returns iterator");
+ static_assert(std::is_same<decltype(cit), test_type::const_iterator>::value,
+ "const upper_bound returns const_iterator");
}
void
cit = cx.equal_range(2L);
VERIFY( cit.first == cit.second && cit.first != cx.end() );
- VERIFY( Cmp::count == 0);
+ VERIFY( Cmp::count == 0 );
+
+ using pair = std::pair<test_type::iterator, test_type::iterator>;
+ static_assert(std::is_same<decltype(it), pair>::value,
+ "equal_range returns pair<iterator, iterator>");
+ using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+ static_assert(std::is_same<decltype(cit), cpair>::value,
+ "const equal_range returns pair<const_iterator, const_iterator>");
}
+void
+test06()
+{
+ // https://gcc.gnu.org/ml/libstdc++/2015-01/msg00176.html
+ // Verify the new function template overloads do not cause problems
+ // when the comparison function is not transparent.
+ struct I
+ {
+ int i;
+ operator int() const { return i; }
+ };
+
+ std::set<int> s;
+ I 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
main()
test03();
test04();
test05();
+ test06();
+ test07();
}