[libcxx] r322492 - More constexpr algorithms from P0202. any_of/all_of/none_of.
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 15 09:20:37 PST 2018
Author: marshall
Date: Mon Jan 15 09:20:36 2018
New Revision: 322492
URL: http://llvm.org/viewvc/llvm-project?rev=322492&view=rev
Log:
More constexpr algorithms from P0202. any_of/all_of/none_of.
Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=322492&r1=322491&r2=322492&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Jan 15 09:20:36 2018
@@ -20,15 +20,15 @@ namespace std
{
template <class InputIterator, class Predicate>
- bool
+ constexpr bool // constexpr in C++20
all_of(InputIterator first, InputIterator last, Predicate pred);
template <class InputIterator, class Predicate>
- bool
+ constexpr bool // constexpr in C++20
any_of(InputIterator first, InputIterator last, Predicate pred);
template <class InputIterator, class Predicate>
- bool
+ constexpr bool // constexpr in C++20
none_of(InputIterator first, InputIterator last, Predicate pred);
template <class InputIterator, class Function>
@@ -919,7 +919,7 @@ inline _LIBCPP_INLINE_VISIBILITY int __p
// all_of
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -932,7 +932,7 @@ all_of(_InputIterator __first, _InputIte
// any_of
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -945,7 +945,7 @@ any_of(_InputIterator __first, _InputIte
// none_of
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
Modified: libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp?rev=322492&r1=322491&r2=322492&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp Mon Jan 15 09:20:36 2018
@@ -16,16 +16,27 @@
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
struct test1
{
- bool operator()(const int& i) const
+ TEST_CONSTEXPR bool operator()(const int& i) const
{
return i % 2 == 0;
}
};
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR int test_constexpr() {
+ int ia[] = {2, 4, 6, 8};
+ int ib[] = {2, 4, 5, 8};
+ return std::all_of(std::begin(ia), std::end(ia), test1())
+ && !std::all_of(std::begin(ib), std::end(ib), test1())
+ ;
+ }
+#endif
+
int main()
{
{
@@ -44,4 +55,8 @@ int main()
assert(std::all_of(input_iterator<const int*>(ia),
input_iterator<const int*>(ia), test1()) == true);
}
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
Modified: libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp?rev=322492&r1=322491&r2=322492&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp Mon Jan 15 09:20:36 2018
@@ -16,16 +16,27 @@
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
struct test1
{
- bool operator()(const int& i) const
+ TEST_CONSTEXPR bool operator()(const int& i) const
{
return i % 2 == 0;
}
};
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR int test_constexpr() {
+ int ia[] = {2, 4, 6, 8};
+ int ib[] = {1, 3, 5, 7};
+ return std::any_of(std::begin(ia), std::end(ia), test1())
+ && !std::any_of(std::begin(ib), std::end(ib), test1())
+ ;
+ }
+#endif
+
int main()
{
{
@@ -52,4 +63,8 @@ int main()
assert(std::any_of(input_iterator<const int*>(ia),
input_iterator<const int*>(ia), test1()) == false);
}
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
Modified: libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp?rev=322492&r1=322491&r2=322492&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.none_of/none_of.pass.cpp Mon Jan 15 09:20:36 2018
@@ -16,16 +16,27 @@
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
struct test1
{
- bool operator()(const int& i) const
+ TEST_CONSTEXPR bool operator()(const int& i) const
{
return i % 2 == 0;
}
};
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR int test_constexpr() {
+ int ia[] = {1, 3, 6, 7};
+ int ib[] = {1, 3, 5, 7};
+ return !std::none_of(std::begin(ia), std::end(ia), test1())
+ && std::none_of(std::begin(ib), std::end(ib), test1())
+ ;
+ }
+#endif
+
int main()
{
{
@@ -52,4 +63,8 @@ int main()
assert(std::none_of(input_iterator<const int*>(ia),
input_iterator<const int*>(ia), test1()) == true);
}
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
More information about the cfe-commits
mailing list