]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/23_containers/set/operations/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / set / operations / 2.cc
index 752bc7dd7a62d1967c2b60086d1cdaeaec7280f1..22ae33700ebaae2ea3b4ff72753506a072de36d1 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -15,7 +15,7 @@
 // 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>
@@ -53,7 +53,12 @@ test01()
   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
@@ -71,7 +76,7 @@ test02()
   cn = cx.count(2L);
   VERIFY( cn == 0 );
 
-  VERIFY( Cmp::count == 0);
+  VERIFY( Cmp::count == 0 );
 }
 
 void
@@ -89,7 +94,12 @@ test03()
   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
@@ -107,7 +117,12 @@ test04()
   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
@@ -125,9 +140,54 @@ test05()
   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()
@@ -137,4 +197,6 @@ main()
   test03();
   test04();
   test05();
+  test06();
+  test07();
 }