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

Thomas Anderson via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 18 17:52:54 PDT 2019


Author: thomasanderson
Date: Thu Apr 18 17:52:54 2019
New Revision: 358725

URL: http://llvm.org/viewvc/llvm-project?rev=358725&view=rev
Log:
[libc++] Make __debug_less::operator() constexpr

This is a followup to [1] which added a new `__debug_less::operator()` overload.
[2] added `_LIBCPP_CONSTEXPR_AFTER_CXX17` to the original
`__debug_less::operator()` between the time of writing [1] and landing it.  This
change adds `_LIBCPP_CONSTEXPR_AFTER_CXX17` to the new overload too.

[1] https://reviews.llvm.org/rL358423
[2] https://reviews.llvm.org/rL358252

Differential Revision: https://reviews.llvm.org/D60724

Modified:
    libcxx/trunk/include/algorithm
    libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=358725&r1=358724&r2=358725&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Thu Apr 18 17:52:54 2019
@@ -785,6 +785,7 @@ struct __debug_less
     __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);

Modified: libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp?rev=358725&r1=358724&r2=358725&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp Thu Apr 18 17:52:54 2019
@@ -268,6 +268,16 @@ void test_value_categories() {
     assert(dl(static_cast<int&&>(1), static_cast<const int&&>(2)));
 }
 
+#if TEST_STD_VER > 17
+constexpr bool test_constexpr() {
+    std::less<> cmp{};
+    __debug_less<std::less<> > dcmp(cmp);
+    assert(dcmp(1, 2));
+    assert(!dcmp(1, 1));
+    return true;
+}
+#endif
+
 int main(int, char**) {
     test_passing();
     test_failing();
@@ -275,5 +285,8 @@ int main(int, char**) {
     test_non_const_arg_cmp();
     test_value_iterator();
     test_value_categories();
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr(), "");
+#endif
     return 0;
 }




More information about the libcxx-commits mailing list