More P0202 constexpr work. This commit adds fill/fill_n/generate/generate_n/unique/unique_copy. I removed a specialization of fill_n that recognized when we were dealing with raw pointers and 1 byte trivially-assignable types and did a memset, because the compiler will do that optimization for us.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323050 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2018-01-20 20:14:32 +00:00
parent a75d61347e
commit 48a4655868
9 changed files with 173 additions and 44 deletions

View File

@@ -12,19 +12,33 @@
// template<ForwardIterator Iter, Callable Generator>
// requires OutputIterator<Iter, Generator::result_type>
// && CopyConstructible<Generator>
// void
// constexpr void // constexpr after c++17
// generate(Iter first, Iter last, Generator gen);
#include <algorithm>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
struct gen_test
{
int operator()() const {return 1;}
TEST_CONSTEXPR int operator()() const {return 1;}
};
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int ia[] = {0, 1, 2, 3, 4};
std::generate(std::begin(ia), std::end(ia), gen_test());
return std::all_of(std::begin(ia), std::end(ia), [](int x) { return x == 1; })
;
}
#endif
template <class Iter>
void
test()
@@ -44,4 +58,8 @@ int main()
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}

View File

@@ -12,7 +12,7 @@
// template<class Iter, IntegralLike Size, Callable Generator>
// requires OutputIterator<Iter, Generator::result_type>
// && CopyConstructible<Generator>
// void
// constexpr void // constexpr after c++17
// generate_n(Iter first, Size n, Generator gen);
#ifdef _MSC_VER
@@ -28,9 +28,25 @@
struct gen_test
{
int operator()() const {return 2;}
TEST_CONSTEXPR int operator()() const {return 2;}
};
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
const size_t N = 5;
int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger than N
auto it = std::generate_n(std::begin(ib), N, gen_test());
return it == (std::begin(ib) + N)
&& std::all_of(std::begin(ib), it, [](int x) { return x == 2; })
&& *it == 0 // don't overwrite the last value in the output array
;
}
#endif
template <class Iter, class Size>
void
test2()
@@ -64,4 +80,8 @@ int main()
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
}