Add move-only types test for transform_reduce bop/uop.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@321848 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,7 +19,9 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include "MoveOnly.h"
|
||||||
#include "test_iterators.h"
|
#include "test_iterators.h"
|
||||||
|
|
||||||
struct identity
|
struct identity
|
||||||
@@ -81,6 +83,15 @@ void test_return_type()
|
|||||||
decltype(std::transform_reduce(p, p, Init{}, std::plus<>(), identity()))> );
|
decltype(std::transform_reduce(p, p, Init{}, std::plus<>(), identity()))> );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_move_only_types()
|
||||||
|
{
|
||||||
|
MoveOnly ia[] = {{1}, {2}, {3}};
|
||||||
|
assert(60 ==
|
||||||
|
std::transform_reduce(std::begin(ia), std::end(ia), MoveOnly{0},
|
||||||
|
[](const MoveOnly& lhs, const MoveOnly& rhs) { return MoveOnly{lhs.get() + rhs.get()}; },
|
||||||
|
[](const MoveOnly& target) { return MoveOnly{target.get() * 10}; }).get());
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test_return_type<char, int>();
|
test_return_type<char, int>();
|
||||||
@@ -105,4 +116,6 @@ int main()
|
|||||||
unsigned res = std::transform_reduce(v.begin(), v.end(), 1U, std::multiplies<>(), twice());
|
unsigned res = std::transform_reduce(v.begin(), v.end(), 1U, std::multiplies<>(), twice());
|
||||||
assert(res == 46080); // 6! * 64 will not fit into a char
|
assert(res == 46080); // 6! * 64 will not fit into a char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_move_only_types();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user