[libcxx-commits] [PATCH] D60724: [libc++] Make __debug_less::operator() constexpr

Tom Anderson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 16 11:55:18 PDT 2019


thomasanderson updated this revision to Diff 195426.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60724/new/

https://reviews.llvm.org/D60724

Files:
  libcxx/include/algorithm
  libcxx/test/libcxx/algorithms/debug_less.pass.cpp


Index: libcxx/test/libcxx/algorithms/debug_less.pass.cpp
===================================================================
--- libcxx/test/libcxx/algorithms/debug_less.pass.cpp
+++ libcxx/test/libcxx/algorithms/debug_less.pass.cpp
@@ -268,6 +268,24 @@
     assert(dl(static_cast<int&&>(1), static_cast<const int&&>(2)));
 }
 
+#if TEST_STD_VER > 17
+struct ConstexprComparator {
+    constexpr bool operator()(int const& lhs, int const& rhs) const {
+        return lhs < rhs;
+    }
+};
+
+void test_constexpr() {
+    auto compare = ConstexprComparator{};
+    constexpr bool b1 = __debug_less{compare}(1, 2);
+    assert(b1);
+    constexpr int i1 = 1;
+    constexpr int i2 = 2;
+    constexpr bool b2 = __debug_less{compare}(i2, i1);
+    assert(!b2);
+}
+#endif
+
 int main(int, char**) {
     test_passing();
     test_failing();
@@ -275,5 +293,8 @@
     test_non_const_arg_cmp();
     test_value_iterator();
     test_value_categories();
+#if TEST_STD_VER > 17
+    test_constexpr();
+#endif
     return 0;
 }
Index: libcxx/include/algorithm
===================================================================
--- libcxx/include/algorithm
+++ libcxx/include/algorithm
@@ -785,6 +785,7 @@
     __debug_less(_Compare& __c) : __comp_(__c) {}
 
     template <class _Tp, class _Up>
+    _LIBCPP_CONSTEXPR_AFTER_CXX17
     bool operator()(const _Tp& __x,  const _Up& __y)
     {
         bool __r = __comp_(__x, __y);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60724.195426.patch
Type: text/x-patch
Size: 1423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190416/0c66c4df/attachment.bin>


More information about the libcxx-commits mailing list