aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/20_util')
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/identity/1.cc40
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc77
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater.cc82
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater_equal.cc82
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc82
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less_equal.cc82
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc77
7 files changed, 522 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/identity/1.cc b/libstdc++-v3/testsuite/20_util/function_objects/identity/1.cc
new file mode 100644
index 00000000000..fd9b79f1fcd
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/identity/1.cc
@@ -0,0 +1,40 @@
+// Copyright (C) 2019 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+
+// C++20 [func.identity]
+static_assert( std::is_default_constructible_v<std::identity> );
+static_assert( std::is_copy_constructible_v<std::identity> );
+static_assert( std::is_move_constructible_v<std::identity> );
+static_assert( std::is_copy_assignable_v<std::identity> );
+static_assert( std::is_move_assignable_v<std::identity> );
+
+static_assert( !std::is_invocable_v<std::identity> );
+static_assert( !std::is_invocable_v<std::identity, int&, int&> );
+static_assert( std::is_nothrow_invocable_r_v<int&, std::identity&, int&> );
+static_assert( std::is_nothrow_invocable_r_v<const long&, std::identity, const long&> );
+static_assert( std::is_nothrow_invocable_r_v<short&&, const std::identity&, short> );
+static_assert( std::is_nothrow_invocable_r_v<const char&&, const std::identity, const char> );
+
+int i;
+static_assert( std::addressof(std::identity{}(i)) == std::addressof(i) );
+
+using T = std::identity::is_transparent; // required typedef
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc
new file mode 100644
index 00000000000..c3ceb316a58
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc
@@ -0,0 +1,77 @@
+// Copyright (C) 2019 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+// C++20 [range.cmp]
+
+using F = std::ranges::equal_to;
+static_assert( std::is_default_constructible_v<F> );
+static_assert( std::is_copy_constructible_v<F> );
+static_assert( std::is_move_constructible_v<F> );
+static_assert( std::is_copy_assignable_v<F> );
+static_assert( std::is_move_assignable_v<F> );
+
+static_assert( ! std::is_invocable_v<F> );
+static_assert( ! std::is_invocable_v<F, int&> );
+static_assert( ! std::is_invocable_v<F, int, void> );
+static_assert( ! std::is_invocable_v<F, int, void*> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, int&, int> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F, const long&, char> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F&, short, int&> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F, const char, char> );
+
+using T = F::is_transparent; // required typedef
+
+static_assert( std::ranges::equal_to{}(99, 99.0) );
+static_assert( ! std::ranges::equal_to{}(99, 99.01) );
+static_assert( ! std::ranges::equal_to{}(99, 140L) );
+
+void
+test01()
+{
+ F f;
+ int a[2]{};
+ VERIFY( f(&a, (void*)&a[0]) );
+ VERIFY( ! f(&a, (void*)&a[1]) );
+ VERIFY( f(&a + 1, (void*)(a + 2)) );
+}
+
+struct X { };
+int operator==(X, X) noexcept { return 2; }
+int operator!=(X, X) { return 0; }
+
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, X, X> );
+
+void
+test02()
+{
+ X x;
+ F f;
+ VERIFY( f(x, x) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater.cc
new file mode 100644
index 00000000000..87fd518e146
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater.cc
@@ -0,0 +1,82 @@
+// Copyright (C) 2019 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+// C++20 [range.cmp]
+
+using F = std::ranges::greater;
+static_assert( std::is_default_constructible_v<F> );
+static_assert( std::is_copy_constructible_v<F> );
+static_assert( std::is_move_constructible_v<F> );
+static_assert( std::is_copy_assignable_v<F> );
+static_assert( std::is_move_assignable_v<F> );
+
+static_assert( ! std::is_invocable_v<F> );
+static_assert( ! std::is_invocable_v<F, int&> );
+static_assert( ! std::is_invocable_v<F, int, void> );
+static_assert( ! std::is_invocable_v<F, int, void*> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, int&, int> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F, const long&, char> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F&, short, int&> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F, const char, char> );
+
+using T = F::is_transparent; // required typedef
+
+static_assert( ! std::ranges::greater{}(99, 99.0) );
+static_assert( std::ranges::greater{}(99.01, 99) );
+static_assert( std::ranges::greater{}(990, 140L) );
+
+void
+test01()
+{
+ F f;
+ int a[2]{};
+ VERIFY( ! f(&a, (void*)&a[0]) );
+ VERIFY( f((void*)&a[1], &a) );
+ VERIFY( f(&a + 1, (void*)(a + 1)) );
+ VERIFY( ! f(&a, (void*)(a + 1)) );
+}
+
+struct X { };
+int operator==(X, X) { return 2; }
+int operator!=(X, X) { return 0; }
+int operator<(X, X) noexcept { return 0; }
+int operator>(X, X) { return 0; }
+int operator<=(X, X) { return 3; }
+int operator>=(X, X) { return 4; }
+
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, X, X> );
+
+void
+test02()
+{
+ X x;
+ F f;
+ VERIFY( ! f(x, x) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater_equal.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater_equal.cc
new file mode 100644
index 00000000000..a1972ab1c09
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater_equal.cc
@@ -0,0 +1,82 @@
+// Copyright (C) 2019 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+// C++20 [range.cmp]
+
+using F = std::ranges::greater_equal;
+static_assert( std::is_default_constructible_v<F> );
+static_assert( std::is_copy_constructible_v<F> );
+static_assert( std::is_move_constructible_v<F> );
+static_assert( std::is_copy_assignable_v<F> );
+static_assert( std::is_move_assignable_v<F> );
+
+static_assert( ! std::is_invocable_v<F> );
+static_assert( ! std::is_invocable_v<F, int&> );
+static_assert( ! std::is_invocable_v<F, int, void> );
+static_assert( ! std::is_invocable_v<F, int, void*> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, int&, int> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F, const long&, char> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F&, short, int&> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F, const char, char> );
+
+using T = F::is_transparent; // required typedef
+
+static_assert( std::ranges::greater_equal{}(99, 99.0) );
+static_assert( std::ranges::greater_equal{}(99.01, 99) );
+static_assert( ! std::ranges::greater_equal{}(99, 140L) );
+
+void
+test01()
+{
+ F f;
+ int a[2]{};
+ VERIFY( f(&a, (void*)&a[0]) );
+ VERIFY( f((void*)&a[1], &a) );
+ VERIFY( f(&a + 1, (void*)(a + 1)) );
+ VERIFY( ! f(&a, (void*)(a + 1)) );
+}
+
+struct X { };
+int operator==(X, X) { return 2; }
+int operator!=(X, X) { return 0; }
+int operator<(X, X) noexcept { return 0; }
+int operator>(X, X) { return 0; }
+int operator<=(X, X) { return 3; }
+int operator>=(X, X) { return 4; }
+
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, X, X> );
+
+void
+test02()
+{
+ X x;
+ F f;
+ VERIFY( f(x, x) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc
new file mode 100644
index 00000000000..e484628f76f
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc
@@ -0,0 +1,82 @@
+// Copyright (C) 2019 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+// C++20 [range.cmp]
+
+using F = std::ranges::less;
+static_assert( std::is_default_constructible_v<F> );
+static_assert( std::is_copy_constructible_v<F> );
+static_assert( std::is_move_constructible_v<F> );
+static_assert( std::is_copy_assignable_v<F> );
+static_assert( std::is_move_assignable_v<F> );
+
+static_assert( ! std::is_invocable_v<F> );
+static_assert( ! std::is_invocable_v<F, int&> );
+static_assert( ! std::is_invocable_v<F, int, void> );
+static_assert( ! std::is_invocable_v<F, int, void*> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, int&, int> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F, const long&, char> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F&, short, int&> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F, const char, char> );
+
+using T = F::is_transparent; // required typedef
+
+static_assert( ! std::ranges::less{}(99, 99.0) );
+static_assert( std::ranges::less{}(99, 99.01) );
+static_assert( std::ranges::less{}(99, 140L) );
+
+void
+test01()
+{
+ F f;
+ int a[2]{};
+ VERIFY( ! f(&a, (void*)&a[0]) );
+ VERIFY( f(&a, (void*)&a[1]) );
+ VERIFY( ! f(&a + 1, (void*)(a + 2)) );
+ VERIFY( f(&a, (void*)(a + 1)) );
+}
+
+struct X { };
+int operator==(X, X) { return 2; }
+int operator!=(X, X) { return 0; }
+int operator<(X, X) noexcept { return 0; }
+int operator>(X, X) { return 0; }
+int operator<=(X, X) { return 3; }
+int operator>=(X, X) { return 4; }
+
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, X, X> );
+
+void
+test02()
+{
+ X x;
+ F f;
+ VERIFY( ! f(x, x) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less_equal.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less_equal.cc
new file mode 100644
index 00000000000..7f5bee68eb4
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less_equal.cc
@@ -0,0 +1,82 @@
+// Copyright (C) 2019 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+// C++20 [range.cmp]
+
+using F = std::ranges::less_equal;
+static_assert( std::is_default_constructible_v<F> );
+static_assert( std::is_copy_constructible_v<F> );
+static_assert( std::is_move_constructible_v<F> );
+static_assert( std::is_copy_assignable_v<F> );
+static_assert( std::is_move_assignable_v<F> );
+
+static_assert( ! std::is_invocable_v<F> );
+static_assert( ! std::is_invocable_v<F, int&> );
+static_assert( ! std::is_invocable_v<F, int, void> );
+static_assert( ! std::is_invocable_v<F, int, void*> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, int&, int> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F, const long&, char> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F&, short, int&> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F, const char, char> );
+
+using T = F::is_transparent; // required typedef
+
+static_assert( std::ranges::less_equal{}(99, 99.0) );
+static_assert( ! std::ranges::less_equal{}(99.01, 99) );
+static_assert( std::ranges::less_equal{}(99, 140L) );
+
+void
+test01()
+{
+ F f;
+ int a[2]{};
+ VERIFY( f(&a, (void*)&a[0]) );
+ VERIFY( ! f((void*)&a[1], &a) );
+ VERIFY( ! f(&a + 1, (void*)(a + 1)) );
+ VERIFY( f(&a, (void*)(a + 1)) );
+}
+
+struct X { };
+int operator==(X, X) { return 2; }
+int operator!=(X, X) { return 0; }
+int operator<(X, X) noexcept { return 0; }
+int operator>(X, X) { return 0; }
+int operator<=(X, X) { return 3; }
+int operator>=(X, X) { return 4; }
+
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, X, X> );
+
+void
+test02()
+{
+ X x;
+ F f;
+ VERIFY( f(x, x) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc
new file mode 100644
index 00000000000..857e63426aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc
@@ -0,0 +1,77 @@
+// Copyright (C) 2019 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+// C++20 [range.cmp]
+
+using F = std::ranges::not_equal_to;
+static_assert( std::is_default_constructible_v<F> );
+static_assert( std::is_copy_constructible_v<F> );
+static_assert( std::is_move_constructible_v<F> );
+static_assert( std::is_copy_assignable_v<F> );
+static_assert( std::is_move_assignable_v<F> );
+
+static_assert( ! std::is_invocable_v<F> );
+static_assert( ! std::is_invocable_v<F, int&> );
+static_assert( ! std::is_invocable_v<F, int, void> );
+static_assert( ! std::is_invocable_v<F, int, void*> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, int&, int> );
+static_assert( std::is_nothrow_invocable_r_v<bool, F, const long&, char> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F&, short, int&> );
+static_assert( std::is_nothrow_invocable_r_v<bool, const F, const char, char> );
+
+using T = F::is_transparent; // required typedef
+
+static_assert( ! std::ranges::not_equal_to{}(99, 99.0) );
+static_assert( std::ranges::not_equal_to{}(99, 99.01) );
+static_assert( std::ranges::not_equal_to{}(99, 140L) );
+
+void
+test01()
+{
+ F f;
+ int a[2]{};
+ VERIFY( ! f(&a, (void*)&a[0]) );
+ VERIFY( f(&a, (void*)&a[1]) );
+ VERIFY( ! f(&a + 1, (void*)(a + 2)) );
+}
+
+struct X { };
+int operator==(X, X) noexcept { return 2; }
+int operator!=(X, X) { return 0; }
+
+static_assert( std::is_nothrow_invocable_r_v<bool, F&, X, X> );
+
+void
+test02()
+{
+ X x;
+ F f;
+ VERIFY( ! f(x, x) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}