mirror of
https://github.com/darlinghq/darling-libcxx.git
synced 2024-11-23 20:09:41 +00:00
Fix incorrect handling of move-only types in transform_reduce iter iter iter init, and add test.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@321851 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b68e9c13a0
commit
70a8aae298
@ -252,7 +252,7 @@ _Tp
|
||||
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _Tp __init)
|
||||
{
|
||||
return _VSTD::transform_reduce(__first1, __last1, __first2, __init,
|
||||
return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init),
|
||||
_VSTD::plus<>(), _VSTD::multiplies<>());
|
||||
}
|
||||
#endif
|
||||
|
@ -17,7 +17,9 @@
|
||||
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
|
||||
#include "MoveOnly.h"
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class Iter1, class Iter2, class T>
|
||||
@ -56,6 +58,24 @@ void test_return_type()
|
||||
decltype(std::transform_reduce(p, p, p, Init{}))> );
|
||||
}
|
||||
|
||||
inline MoveOnly operator+(const MoveOnly& lhs, const MoveOnly& rhs)
|
||||
{
|
||||
return MoveOnly{lhs.get() + rhs.get()};
|
||||
}
|
||||
|
||||
inline MoveOnly operator*(const MoveOnly& lhs, const MoveOnly& rhs)
|
||||
{
|
||||
return MoveOnly{lhs.get() * rhs.get()};
|
||||
}
|
||||
|
||||
void test_move_only_types()
|
||||
{
|
||||
MoveOnly ia[] = {{1}, {2}, {3}};
|
||||
MoveOnly ib[] = {{1}, {2}, {3}};
|
||||
assert(14 ==
|
||||
std::transform_reduce(std::begin(ia), std::end(ia), std::begin(ib), MoveOnly{0}).get());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_return_type<char, int>();
|
||||
@ -92,4 +112,6 @@ int main()
|
||||
test<const int*, unsigned int *>();
|
||||
test< int*, const unsigned int *>();
|
||||
test< int*, unsigned int *>();
|
||||
|
||||
test_move_only_types();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user