mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 20:29:39 +08: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:
@@ -252,7 +252,7 @@ _Tp
|
|||||||
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
|
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||||
_InputIterator2 __first2, _Tp __init)
|
_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<>());
|
_VSTD::plus<>(), _VSTD::multiplies<>());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include "MoveOnly.h"
|
||||||
#include "test_iterators.h"
|
#include "test_iterators.h"
|
||||||
|
|
||||||
template <class Iter1, class Iter2, class T>
|
template <class Iter1, class Iter2, class T>
|
||||||
@@ -56,6 +58,24 @@ void test_return_type()
|
|||||||
decltype(std::transform_reduce(p, p, p, Init{}))> );
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
test_return_type<char, int>();
|
test_return_type<char, int>();
|
||||||
@@ -92,4 +112,6 @@ int main()
|
|||||||
test<const int*, unsigned int *>();
|
test<const int*, unsigned int *>();
|
||||||
test< int*, const unsigned int *>();
|
test< int*, const unsigned int *>();
|
||||||
test< int*, unsigned int *>();
|
test< int*, unsigned int *>();
|
||||||
|
|
||||||
|
test_move_only_types();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user