Another batch of P0202 constepr algirithms. remove/remove_if/remove_copy/remove_copy_if/reverse_copy, and tests (commented out) for rotate_copy, because that depends on std::copy

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323152 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2018-01-22 21:43:04 +00:00
parent a15161a030
commit 63be4189d8
7 changed files with 127 additions and 18 deletions

View File

@@ -12,16 +12,31 @@
// template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter,
// Predicate<auto, InIter::value_type> Pred>
// requires CopyConstructible<Pred>
// OutIter
// constexpr OutIter // constexpr after C++17
// remove_copy_if(InIter first, InIter last, OutIter result, Pred pred);
#include <algorithm>
#include <functional>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
bool equalToTwo(int v) { return v == 2; }
TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; }
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int ia[] = {1, 3, 5, 2, 5, 6};
int ib[std::size(ia)] = {0};
auto it = std::remove_copy_if(std::begin(ia), std::end(ia), std::begin(ib), equalToTwo);
return std::distance(std::begin(ib), it) == (std::size(ia) - 1) // we removed one element
&& std::none_of(std::begin(ib), it, equalToTwo)
&& std::all_of (it, std::end(ib), [](int a) {return a == 0;})
;
}
#endif
template <class InIter, class OutIter>
void
@@ -72,4 +87,8 @@ int main()
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}