c++ - vector addition assignment with `std::transform` -
which kind of output iterator need utilize in std::transform implement vector add-on assignment:
template<typename t> std::vector<t>& operator+=(std::vector<t>& lhs, std::vector<t> const& rhs) { if (lhs.size() == rhs.size()) { std::transform(lhs.begin(), lhs.end(), rhs.begin(), /*output iterator*/, std::plus<t>()); homecoming lhs; } throw std::invalid_argument("operands must of same size"); } std::transform implemented in next way:
template<class inputit1, class inputit2, class outputit, class binaryoperation> outputit transform(inputit first1, inputit last1, inputit first2, outputit d_first, binaryoperation binary_op) { while (first1 != last1) { *d_first++ = binary_op(*first1++, *first2++); } homecoming d_first; } so, outputit needs start @ lhs.begin() , replace values lhs.end(). i'm sure there kind of standard functionality implemented.
you pass lhs.begin() again: want overwrite existing values of lhs new ones.
c++ c++11 vector stl
No comments:
Post a Comment