mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00
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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user