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:
Billy Robert O'Neal III 2018-01-05 01:31:57 +00:00
parent b68e9c13a0
commit 70a8aae298
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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();
}