[PATCH] D43773: Implement the container bits of P0805R1

2018-03-01 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 136582.
mclow.lists added a comment.

Add the `tuple` bits. Regularize the equality comparisons of the containers; 
i.e, don't try to be clever - let the compiler be clever.


https://reviews.llvm.org/D43773

Files:
  include/array
  include/deque
  include/forward_list
  include/list
  include/tuple
  include/vector
  test/std/containers/sequences/array/compare.fail.cpp
  test/std/containers/sequences/array/compare.pass.cpp
  test/std/containers/sequences/deque/compare.fail.cpp
  test/std/containers/sequences/deque/compare.pass.cpp
  test/std/containers/sequences/forwardlist/compare.fail.cpp
  test/std/containers/sequences/forwardlist/compare.pass.cpp
  test/std/containers/sequences/list/compare.fail.cpp
  test/std/containers/sequences/list/compare.pass.cpp
  test/std/containers/sequences/vector/compare.fail.cpp
  test/std/containers/sequences/vector/compare.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp

Index: test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
@@ -35,6 +35,16 @@
 
 #include "test_macros.h"
 
+
+template 
+void compare (const T1 &t1, const T2 &t2)
+{
+assert((t1  < t2) == ( isLess));
+assert((t1  > t2) == (!isLess && !isEqual));
+assert((t1 <= t2) == ( isLess ||  isEqual));
+assert((t1 >= t2) == (!isLess ||  isEqual));
+}
+
 int main()
 {
 {
@@ -208,5 +218,57 @@
 static_assert(!(t1 >  t2), "");
 static_assert(!(t1 >= t2), "");
 }
+{ // P0805
+typedef std::tuple<> T0;
+typedef std::tuple T1;
+typedef std::tuple T2;
+constexpr T0 t0;
+constexpr T1 t1(1, 2, 3);
+constexpr T2 t2(1, 2);
+constexpr T1 t3(0, 1, 2); // common tail
+
+// less, equal
+compare(t0, t0);
+static_assert(!(t0  < t0), "");
+static_assert(!(t0  > t0), "");
+static_assert( (t0 <= t0), "");
+static_assert( (t0 >= t0), "");
+
+compare(t0, t1);
+static_assert( (t0  < t1), "");
+static_assert(!(t0  > t1), "");
+static_assert( (t0 <= t1), "");
+static_assert(!(t0 >= t1), "");
+
+compare(t1, t0);
+static_assert(!(t1  < t0), "");
+static_assert( (t1  > t0), "");
+static_assert(!(t1 <= t0), "");
+static_assert( (t1 >= t0), "");
+
+compare(t1, t2);
+static_assert(!(t1  < t2), "");
+static_assert( (t1  > t2), "");
+static_assert(!(t1 <= t2), "");
+static_assert( (t1 >= t2), "");
+
+compare(t2, t1);
+static_assert( (t2  < t1), "");
+static_assert(!(t2  > t1), "");
+static_assert( (t2 <= t1), "");
+static_assert(!(t2 >= t1), "");
+
+compare(t2, t3);
+static_assert(!(t2  < t3), "");
+static_assert( (t2  > t3), "");
+static_assert(!(t2 <= t3), "");
+static_assert( (t2 >= t3), "");
+
+compare(t3, t2);
+static_assert( (t3  < t2), "");
+static_assert(!(t3  > t2), "");
+static_assert( (t3 <= t2), "");
+static_assert(!(t3 >= t2), "");
+}
 #endif
 }
Index: test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp
@@ -154,5 +154,20 @@
 static_assert(!(t1 == t2), "");
 static_assert(t1 != t2, "");
 }
+{ // P0805
+typedef std::tuple T1;
+typedef std::tuple T2;
+constexpr T1 t1(1, 2, 3);
+constexpr T2 t2(1.1, 3);
+constexpr T2 t3(1, 2);
+static_assert(!(t1 == t2), "");
+static_assert(!(t2 == t1), "");
+static_assert(!(t1 == t3), "");
+static_assert(!(t3 == t1), "");
+static_assert(  t1 != t2,  "");
+static_assert(  t2 != t1,  "");
+static_assert(  t1 != t3,  "");
+static_assert(  t3 != t1,  "");
+}
 #endif
 }
Index: test/std/containers/sequences/vector/compare.pass.cpp
===
--- test/std/containers/sequences/vector/compare.pass.cpp
+++ test/std/containers/sequences/vector/compare.pass.cpp
@@ -0,0 +1,90 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool 

[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

> Is there a subtle reason for this inconsistency that I'm not seeing?

I suspect that it's because they were written at different times.
(When I say 'written at different times', I mean I adapted the existing `op==` 
for the containers - not that this new code was written at different times)

I'm a fan of the four-legged bits, but in `op==` (except for `forward_list` we 
know the sizes are the same.


https://reviews.llvm.org/D43773



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

I can certainly make them all the same.


https://reviews.llvm.org/D43773



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Tim Song via Phabricator via cfe-commits
tcanens added a comment.

Hmm, for `vector` and `deque`, we define a temporary variable, check that sizes 
match and then use range-and-a-half `equal`:

  const typename vector<_Tp1, _Allocator1>::size_type __sz = __x.size();
  return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), 
__y.begin());

For `list` we check that sizes match and then use range-and-a-half `equal`, but 
don't use a temporary variable:

  return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), 
__y.begin());

For `array` we check that sizes match and then use dual-range `equal`:

  if (_Size1 != _Size2)
  return false;
  return _VSTD::equal(__x.begin(), __x.end(), __y.begin(), __y.end());

Is there a subtle reason for this inconsistency that I'm not seeing?


https://reviews.llvm.org/D43773



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 135941.
mclow.lists added a comment.

forgot to include the changes for `` in the diff.


https://reviews.llvm.org/D43773

Files:
  include/array
  include/deque
  include/forward_list
  include/list
  include/vector
  test/std/containers/sequences/array/compare.fail.cpp
  test/std/containers/sequences/array/compare.pass.cpp
  test/std/containers/sequences/deque/compare.fail.cpp
  test/std/containers/sequences/deque/compare.pass.cpp
  test/std/containers/sequences/forwardlist/compare.fail.cpp
  test/std/containers/sequences/forwardlist/compare.pass.cpp
  test/std/containers/sequences/list/compare.fail.cpp
  test/std/containers/sequences/list/compare.pass.cpp
  test/std/containers/sequences/vector/compare.fail.cpp
  test/std/containers/sequences/vector/compare.pass.cpp

Index: test/std/containers/sequences/vector/compare.pass.cpp
===
--- test/std/containers/sequences/vector/compare.pass.cpp
+++ test/std/containers/sequences/vector/compare.pass.cpp
@@ -0,0 +1,90 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector& x, const vector& y);
+// template  bool operator!=(const vector& x, const vector& y);
+// template  bool operator> (const vector& x, const vector& y);
+// template  bool operator>=(const vector& x, const vector& y);
+// template  bool operator<=(const vector& x, const vector& y);
+// 
+// C++20
+// template
+//   bool operator==(const vector& x, const vector& y);
+// template
+//   bool operator< (const vector& x, const vector& y);
+// template
+//   bool operator!=(const vector& x, const vector& y);
+// template
+//   bool operator> (const vector& x, const vector& y);
+// template
+//   bool operator>=(const vector& x, const vector& y);
+// template
+//   bool operator<=(const vector& x, const vector& y);
+
+
+#include 
+#include 
+
+#include "min_allocator.h"
+#include "test_macros.h"
+
+template 
+void test_compare(const Vector& LHS, const Vector& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+template 
+void test_compare(const Vector1& LHS, const Vector2& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+int main()
+{
+  {
+typedef int T;
+typedef std::vector C;
+C c0 = {};
+C c1 = {1, 2, 3};
+C c2 = {1, 2, 3};
+C c3 = {3, 2, 1};
+C c4 = {1, 2, 1};
+test_compare(c0, c1, true, false);
+test_compare(c1, c2, false, true);
+test_compare(c1, c3, true, false);
+test_compare(c1, c4, false, false);
+  }
+
+#if TEST_STD_VER > 17
+  {
+std::vector   c0 = {};
+std::vector   c1 = {4};
+std::vector  c2 = {4L};
+std::vector c3 = {2};
+std::vector> c4 = {4};
+test_compare(c0, c1, true, false);  // same type, different lengths
+test_compare(c0, c2, true, false);  // different type, different lengths
+test_compare(c1, c2, false, true);  // different types, same length, same values
+test_compare(c1, c3, false, false); // different types, same length, different values
+test_compare(c1, c4, false, true);  // different types, same length, same value, different allocator
+  }
+#endif
+}
Index: test/std/containers/sequences/vector/compare.fail.cpp
===
--- test/std/containers/sequences/vector/compare.fail.cpp
+++ test/std/containers/sequences/vector/compare.fail.cpp
@@ -0,0 +1,70 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector& x, const vector& y);
+// template  bool operator!=(const vector& x, const vector& y);
+// template  bool operator> (const vector& x, const vector& y);
+// template  bool operator>=(const vector& x, const vector& y);
+// template  bool o

[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.
mclow.lists added a reviewer: EricWF.

P0805R1  
is about comparing heterogenous containers.

This is the implementation for `array`, `vector`, `deque`, `list` and 
`forward_list`.
The `tuple` bits will follow soon.

I hope to land this immediately after it is adopted in Jacksonville.


https://reviews.llvm.org/D43773

Files:
  include/array
  include/deque
  include/list
  include/vector
  test/std/containers/sequences/array/compare.fail.cpp
  test/std/containers/sequences/array/compare.pass.cpp
  test/std/containers/sequences/deque/compare.fail.cpp
  test/std/containers/sequences/deque/compare.pass.cpp
  test/std/containers/sequences/forwardlist/compare.fail.cpp
  test/std/containers/sequences/forwardlist/compare.pass.cpp
  test/std/containers/sequences/list/compare.fail.cpp
  test/std/containers/sequences/list/compare.pass.cpp
  test/std/containers/sequences/vector/compare.fail.cpp
  test/std/containers/sequences/vector/compare.pass.cpp

Index: test/std/containers/sequences/vector/compare.pass.cpp
===
--- test/std/containers/sequences/vector/compare.pass.cpp
+++ test/std/containers/sequences/vector/compare.pass.cpp
@@ -0,0 +1,90 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector& x, const vector& y);
+// template  bool operator!=(const vector& x, const vector& y);
+// template  bool operator> (const vector& x, const vector& y);
+// template  bool operator>=(const vector& x, const vector& y);
+// template  bool operator<=(const vector& x, const vector& y);
+// 
+// C++20
+// template
+//   bool operator==(const vector& x, const vector& y);
+// template
+//   bool operator< (const vector& x, const vector& y);
+// template
+//   bool operator!=(const vector& x, const vector& y);
+// template
+//   bool operator> (const vector& x, const vector& y);
+// template
+//   bool operator>=(const vector& x, const vector& y);
+// template
+//   bool operator<=(const vector& x, const vector& y);
+
+
+#include 
+#include 
+
+#include "min_allocator.h"
+#include "test_macros.h"
+
+template 
+void test_compare(const Vector& LHS, const Vector& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+template 
+void test_compare(const Vector1& LHS, const Vector2& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+int main()
+{
+  {
+typedef int T;
+typedef std::vector C;
+C c0 = {};
+C c1 = {1, 2, 3};
+C c2 = {1, 2, 3};
+C c3 = {3, 2, 1};
+C c4 = {1, 2, 1};
+test_compare(c0, c1, true, false);
+test_compare(c1, c2, false, true);
+test_compare(c1, c3, true, false);
+test_compare(c1, c4, false, false);
+  }
+
+#if TEST_STD_VER > 17
+  {
+std::vector   c0 = {};
+std::vector   c1 = {4};
+std::vector  c2 = {4L};
+std::vector c3 = {2};
+std::vector> c4 = {4};
+test_compare(c0, c1, true, false);  // same type, different lengths
+test_compare(c0, c2, true, false);  // different type, different lengths
+test_compare(c1, c2, false, true);  // different types, same length, same values
+test_compare(c1, c3, false, false); // different types, same length, different values
+test_compare(c1, c4, false, true);  // different types, same length, same value, different allocator
+  }
+#endif
+}
Index: test/std/containers/sequences/vector/compare.fail.cpp
===
--- test/std/containers/sequences/vector/compare.fail.cpp
+++ test/std/containers/sequences/vector/compare.fail.cpp
@@ -0,0 +1,70 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector