First part of P0202: Adding constexpr modifiers to functions in <algorithm> and <utility>. This commit is all the is_XXX algorithms.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@322489 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2018-01-15 16:16:32 +00:00
parent cce11ce7c2
commit 8d0d82585a
13 changed files with 222 additions and 62 deletions

View File

@@ -10,7 +10,7 @@
// <algorithm>
// template <class InputIterator, class Predicate>
// bool
// constpexr bool // constexpr after C++17
// is_partitioned(InputIterator first, InputIterator last, Predicate pred);
#include <algorithm>
@@ -18,13 +18,24 @@
#include <cstddef>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#include "counting_predicates.hpp"
struct is_odd {
bool operator()(const int &i) const { return i & 1; }
TEST_CONSTEXPR bool operator()(const int &i) const { return i & 1; }
};
#if TEST_STD_VER > 17
TEST_CONSTEXPR int test_constexpr() {
int ia[] = {1, 3, 5, 2, 4, 6};
int ib[] = {1, 2, 3, 4, 5, 6};
return std::is_partitioned(std::begin(ia), std::end(ia), is_odd())
&& !std::is_partitioned(std::begin(ib), std::end(ib), is_odd());
}
#endif
int main() {
{
const int ia[] = {1, 2, 3, 4, 5, 6};
@@ -80,4 +91,8 @@ int main() {
assert(static_cast<std::ptrdiff_t>(pred.count()) <=
std::distance(std::begin(ia), std::end(ia)));
}
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}