summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/language.support/cmp/cmp.common
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2018-04-06 21:37:23 +0000
committerEric Fiselier <eric@efcs.ca>2018-04-06 21:37:23 +0000
commit0913ca197855626c93fdae4184ae80ff5a26503a (patch)
treee7765626e6ab2a71e67babcfefd2ab0ecb7758e1 /libcxx/test/std/language.support/cmp/cmp.common
parent66f53d71f7e0ff1c2811ec6741af511c588fd038 (diff)
downloadbcm5719-llvm-0913ca197855626c93fdae4184ae80ff5a26503a.tar.gz
bcm5719-llvm-0913ca197855626c93fdae4184ae80ff5a26503a.zip
Implement P0768r1: Library support for the Spaceship Operator.
this patch adds the <compare> header and implements all of it except for [comp.alg]. As I understand it, the header is needed by the compiler in when implementing the semantics of operator<=>. For that reason I feel it's important to land this header early, despite all compilers lacking support. llvm-svn: 329460
Diffstat (limited to 'libcxx/test/std/language.support/cmp/cmp.common')
-rw-r--r--libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp
new file mode 100644
index 00000000000..f146dace65e
--- /dev/null
+++ b/libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// <compare>
+
+// template <class ...Ts> struct common_comparison_category
+// template <class ...Ts> using common_comparison_category_t
+
+
+#include <compare>
+#include <type_traits>
+#include <cassert>
+
+#include "test_macros.h"
+
+const volatile void* volatile sink;
+
+template <class Expect, class ...Args>
+void test_cat() {
+ using Cat = std::common_comparison_category<Args...>;
+ using CatT = typename Cat::type;
+ static_assert(std::is_same<CatT, std::common_comparison_category_t<Args...>>::value, "");
+ static_assert(std::is_same<CatT, Expect>::value, "expected different category");
+};
+
+
+// [class.spaceship]p4: The 'common comparison type' U of a possibly-empty list
+// of 'n' types T0, T1, ..., TN, is defined as follows:
+int main() {
+ using WE = std::weak_equality;
+ using SE = std::strong_equality;
+ using PO = std::partial_ordering;
+ using WO = std::weak_ordering;
+ using SO = std::strong_ordering;
+
+ // [class.spaceship]p4.1: If any Ti is not a comparison category tpe, U is void.
+ {
+ test_cat<void, void>();
+ test_cat<void, int*>();
+ test_cat<void, SO&>();
+ test_cat<void, SO const>();
+ test_cat<void, SO*>();
+ test_cat<void, SO, void, SO>();
+ }
+
+ // [class.spaceship]p4.2: Otherwise, if at least on Ti is
+ // std::weak_equality, or at least one Ti is std::strong_equality and at least
+ // one Tj is std::partial_ordering or std::weak_ordering, U is std::weak_equality
+ {
+ test_cat<WE, WE>();
+ test_cat<WE, SO, WE, SO>();
+ test_cat<WE, SE, SO, PO>();
+ test_cat<WE, WO, SO, SE>();
+ }
+
+ // [class.spaceship]p4.3: Otherwise, if at least one Ti is std::strong_equality,
+ // U is std::strong_equality
+ {
+ test_cat<SE, SE>();
+ test_cat<SE, SO, SE, SO>();
+ }
+
+ // [class.spaceship]p4.4: Otherwise, if at least one Ti is std::partial_ordering,
+ // U is std::partial_ordering
+ {
+ test_cat<PO, PO>();
+ test_cat<PO, SO, PO, SO>();
+ test_cat<PO, WO, PO, SO>();
+ }
+
+ // [class.spaceship]p4.5: Otherwise, if at least one Ti is std::weak_ordering,
+ // U is std::weak_ordering
+ {
+ test_cat<WO, WO>();
+ test_cat<WO, SO, WO, SO>();
+ }
+
+ // [class.spaceship]p4.6: Otherwise, U is std::strong_ordering. [Note: in
+ // particular this is the result when n is 0. -- end note]
+ {
+ test_cat<SO>(); // empty type list
+ test_cat<SO, SO>();
+ test_cat<SO, SO, SO>();
+ }
+}
OpenPOWER on IntegriCloud