[libcxx] r322529 - More constexpr algorithms from P0202: lower_bound, upper_bound, equal_range, binary_search

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 15 18:34:41 PST 2018


Author: marshall
Date: Mon Jan 15 18:34:41 2018
New Revision: 322529

URL: http://llvm.org/viewvc/llvm-project?rev=322529&view=rev
Log:
More constexpr algorithms from P0202: lower_bound, upper_bound, equal_range, binary_search

Modified:
    libcxx/trunk/include/algorithm
    libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 18:34:41 2018
@@ -321,7 +321,7 @@ template <class ForwardIterator, class P
     stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
 
 template<class ForwardIterator, class Predicate>
-    ForwardIterator  // constexpr in C++20
+    constexpr ForwardIterator  // constexpr in C++20
     partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
 
 template <class ForwardIterator>
@@ -383,35 +383,35 @@ template <class RandomAccessIterator, cl
     nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
 
 template <class ForwardIterator, class T>
-    ForwardIterator
+    constexpr ForwardIterator                         // constexpr in C++20
     lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
 
 template <class ForwardIterator, class T, class Compare>
-    ForwardIterator
+    constexpr ForwardIterator                         // constexpr in C++20
     lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
 
 template <class ForwardIterator, class T>
-    ForwardIterator
+    constexpr ForwardIterator                         // constexpr in C++20
     upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
 
 template <class ForwardIterator, class T, class Compare>
-    ForwardIterator
+    constexpr ForwardIterator                         // constexpr in C++20
     upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
 
 template <class ForwardIterator, class T>
-    pair<ForwardIterator, ForwardIterator>
+    constexpr pair<ForwardIterator, ForwardIterator>  // constexpr in C++20
     equal_range(ForwardIterator first, ForwardIterator last, const T& value);
 
 template <class ForwardIterator, class T, class Compare>
-    pair<ForwardIterator, ForwardIterator>
+    constexpr pair<ForwardIterator, ForwardIterator>  // constexpr in C++20
     equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
 
 template <class ForwardIterator, class T>
-    bool
+    constexpr bool                                    // constexpr in C++20
     binary_search(ForwardIterator first, ForwardIterator last, const T& value);
 
 template <class ForwardIterator, class T, class Compare>
-    bool
+    bool  // constexpr in C++20
     binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
 
 template <class InputIterator1, class InputIterator2, class OutputIterator>
@@ -4195,7 +4195,7 @@ _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS
 // lower_bound
 
 template <class _Compare, class _ForwardIterator, class _Tp>
-_ForwardIterator
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 __lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
     typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
@@ -4217,7 +4217,7 @@ __lower_bound(_ForwardIterator __first,
 }
 
 template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
@@ -4232,7 +4232,7 @@ lower_bound(_ForwardIterator __first, _F
 }
 
 template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
 {
@@ -4243,7 +4243,7 @@ lower_bound(_ForwardIterator __first, _F
 // upper_bound
 
 template <class _Compare, class _ForwardIterator, class _Tp>
-_ForwardIterator
+_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
 __upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
     typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
@@ -4265,7 +4265,7 @@ __upper_bound(_ForwardIterator __first,
 }
 
 template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
@@ -4280,7 +4280,7 @@ upper_bound(_ForwardIterator __first, _F
 }
 
 template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _ForwardIterator
 upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
 {
@@ -4291,7 +4291,7 @@ upper_bound(_ForwardIterator __first, _F
 // equal_range
 
 template <class _Compare, class _ForwardIterator, class _Tp>
-pair<_ForwardIterator, _ForwardIterator>
+_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
 __equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
     typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
@@ -4325,7 +4325,7 @@ __equal_range(_ForwardIterator __first,
 }
 
 template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 pair<_ForwardIterator, _ForwardIterator>
 equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
@@ -4340,7 +4340,7 @@ equal_range(_ForwardIterator __first, _F
 }
 
 template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 pair<_ForwardIterator, _ForwardIterator>
 equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
 {
@@ -4351,7 +4351,7 @@ equal_range(_ForwardIterator __first, _F
 // binary_search
 
 template <class _Compare, class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 __binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
@@ -4360,7 +4360,7 @@ __binary_search(_ForwardIterator __first
 }
 
 template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
 {
@@ -4375,7 +4375,7 @@ binary_search(_ForwardIterator __first,
 }
 
 template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool
 binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
 {

Modified: libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp Mon Jan 15 18:34:41 2018
@@ -14,7 +14,7 @@
 //   constexpr bool     // constexpr after c++17
 //   equal(Iter1 first1, Iter1 last1, Iter2 first2);
 //
-//	Introduced in C++14:
+// Introduced in C++14:
 // template<InputIterator Iter1, InputIterator Iter2>
 //   constexpr bool     // constexpr after c++17
 //   equal(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);

Modified: libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.equal/equal_pred.pass.cpp Mon Jan 15 18:34:41 2018
@@ -15,7 +15,7 @@
 //   constexpr bool     // constexpr after c++17
 //   equal(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred);
 //
-//	Introduced in C++14:
+// Introduced in C++14:
 // template<InputIterator Iter1, InputIterator Iter2,
 //          Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
 //   requires CopyConstructible<Pred>

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp Mon Jan 15 18:34:41 2018
@@ -10,9 +10,7 @@
 // <algorithm>
 
 // template<ForwardIterator Iter, class T>
-//   requires HasLess<T, Iter::value_type>
-//         && HasLess<Iter::value_type, T>
-//   bool
+//   constexpr bool      // constexpr after C++17
 //   binary_search(Iter first, Iter last, const T& value);
 
 #include <algorithm>
@@ -20,8 +18,22 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool lt(int a, int b) { return a < b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 3, 6, 7};
+
+    return  std::binary_search(std::begin(ia), std::end(ia), 1)
+        &&  std::binary_search(std::begin(ia), std::end(ia), 3)
+        && !std::binary_search(std::begin(ia), std::end(ia), 9)
+        ;
+    }
+#endif
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value, bool x)
@@ -61,4 +73,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search_comp.pass.cpp Mon Jan 15 18:34:41 2018
@@ -10,9 +10,7 @@
 // <algorithm>
 
 // template<ForwardIterator Iter, class T, CopyConstructible Compare>
-//   requires Predicate<Compare, T, Iter::value_type>
-//         && Predicate<Compare, Iter::value_type, T>
-//   bool
+//   constexpr bool      // constexpr after C++17
 //   binary_search(Iter first, Iter last, const T& value, Compare comp);
 
 #include <algorithm>
@@ -21,8 +19,22 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool lt(int a, int b) { return a < b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 3, 6, 7};
+
+    return  std::binary_search(std::begin(ia), std::end(ia), 1, lt)
+        &&  std::binary_search(std::begin(ia), std::end(ia), 3, lt)
+        && !std::binary_search(std::begin(ia), std::end(ia), 9, lt)
+        ;
+    }
+#endif
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value, bool x)
@@ -62,4 +74,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range.pass.cpp Mon Jan 15 18:34:41 2018
@@ -12,7 +12,7 @@
 // template<ForwardIterator Iter, class T>
 //   requires HasLess<T, Iter::value_type>
 //         && HasLess<Iter::value_type, T>
-//   pair<Iter, Iter>
+//   constexpr pair<Iter, Iter>   // constexpr after c++17
 //   equal_range(Iter first, Iter last, const T& value);
 
 #include <algorithm>
@@ -20,8 +20,22 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool lt(int a, int b) { return a < b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 3, 6, 7};
+
+    return (std::equal_range(std::begin(ia), std::end(ia), 1, lt) == std::pair<int *, int *>(ia+0, ia+1))
+        && (std::equal_range(std::begin(ia), std::end(ia), 3, lt) == std::pair<int *, int *>(ia+1, ia+3))
+        && (std::equal_range(std::begin(ia), std::end(ia), 9, lt) == std::pair<int *, int *>(std::end(ia), std::end(ia)))
+        ;
+    }
+#endif
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value)
@@ -67,4 +81,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/equal.range/equal_range_comp.pass.cpp Mon Jan 15 18:34:41 2018
@@ -10,9 +10,7 @@
 // <algorithm>
 
 // template<ForwardIterator Iter, class T, CopyConstructible Compare>
-//   requires Predicate<Compare, T, Iter::value_type>
-//         && Predicate<Compare, Iter::value_type, T>
-//   pair<Iter, Iter>
+//   constexpr pair<Iter, Iter>   // constexpr after c++17
 //   equal_range(Iter first, Iter last, const T& value, Compare comp);
 
 #include <algorithm>
@@ -21,8 +19,22 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool lt(int a, int b) { return a < b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 3, 6, 7};
+
+    return (std::equal_range(std::begin(ia), std::end(ia), 1, lt) == std::pair<int *, int *>(ia+0, ia+1))
+        && (std::equal_range(std::begin(ia), std::end(ia), 3, lt) == std::pair<int *, int *>(ia+1, ia+3))
+        && (std::equal_range(std::begin(ia), std::end(ia), 9, lt) == std::pair<int *, int *>(std::end(ia), std::end(ia)))
+        ;
+    }
+#endif
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value)
@@ -68,4 +80,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound.pass.cpp Mon Jan 15 18:34:41 2018
@@ -10,8 +10,7 @@
 // <algorithm>
 
 // template<ForwardIterator Iter, class T>
-//   requires HasLess<Iter::value_type, T>
-//   Iter
+//   constexpr Iter    // constexpr after c++17
 //   lower_bound(Iter first, Iter last, const T& value);
 
 #include <algorithm>
@@ -19,8 +18,23 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool eq(int a, int b) { return a == b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 6, 7};
+
+    return (std::lower_bound(std::begin(ia), std::end(ia), 2) == ia+1)
+        && (std::lower_bound(std::begin(ia), std::end(ia), 3) == ia+1)
+        && (std::lower_bound(std::begin(ia), std::end(ia), 9) == std::end(ia))
+        ;
+    }
+#endif
+
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value)
@@ -62,4 +76,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/lower_bound_comp.pass.cpp Mon Jan 15 18:34:41 2018
@@ -9,10 +9,9 @@
 
 // <algorithm>
 
-// template<ForwardIterator Iter, class T>
-//   requires HasLess<Iter::value_type, T>
-//   Iter
-//   lower_bound(Iter first, Iter last, const T& value);
+// template<ForwardIterator Iter, class T, class Compare>
+//   constexpr Iter    // constexpr after c++17
+//   lower_bound(Iter first, Iter last, const T& value, Compare comp);
 
 #include <algorithm>
 #include <functional>
@@ -20,8 +19,22 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool lt(int a, int b) { return a < b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 6, 7};
+
+    return (std::lower_bound(std::begin(ia), std::end(ia), 2, lt) == ia+1)
+        && (std::lower_bound(std::begin(ia), std::end(ia), 3, lt) == ia+1)
+        && (std::lower_bound(std::begin(ia), std::end(ia), 9, lt) == std::end(ia))
+        ;
+    }
+#endif
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value)
@@ -63,4 +76,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound.pass.cpp Mon Jan 15 18:34:41 2018
@@ -10,8 +10,7 @@
 // <algorithm>
 
 // template<ForwardIterator Iter, class T>
-//   requires HasLess<T, Iter::value_type>
-//   Iter
+//   constexpr Iter    // constexpr after c++17
 //   upper_bound(Iter first, Iter last, const T& value);
 
 #include <algorithm>
@@ -19,8 +18,20 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 6, 7};
+
+    return (std::upper_bound(std::begin(ia), std::end(ia), 2) == ia+1)
+        && (std::upper_bound(std::begin(ia), std::end(ia), 3) == ia+2)
+        && (std::upper_bound(std::begin(ia), std::end(ia), 9) == std::end(ia))
+        ;
+    }
+#endif
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value)
@@ -62,4 +73,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp?rev=322529&r1=322528&r2=322529&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.binary.search/upper.bound/upper_bound_comp.pass.cpp Mon Jan 15 18:34:41 2018
@@ -10,8 +10,7 @@
 // <algorithm>
 
 // template<ForwardIterator Iter, class T, Predicate<auto, T, Iter::value_type> Compare>
-//   requires CopyConstructible<Compare>
-//   Iter
+//   constexpr Iter    // constexpr after c++17
 //   upper_bound(Iter first, Iter last, const T& value, Compare comp);
 
 #include <algorithm>
@@ -20,8 +19,22 @@
 #include <cassert>
 #include <cstddef>
 
+#include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool lt(int a, int b) { return a < b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+    int ia[] = {1, 3, 6, 7};
+
+    return (std::upper_bound(std::begin(ia), std::end(ia), 2, lt) == ia+1)
+        && (std::upper_bound(std::begin(ia), std::end(ia), 3, lt) == ia+2)
+        && (std::upper_bound(std::begin(ia), std::end(ia), 9, lt) == std::end(ia))
+        ;
+    }
+#endif
+
 template <class Iter, class T>
 void
 test(Iter first, Iter last, const T& value)
@@ -63,4 +76,8 @@ int main()
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+
+#if TEST_STD_VER > 17
+    static_assert(test_constexpr());
+#endif
 }




More information about the cfe-commits mailing list