Auxiliary Arithmetic Algorithms
negate.hpp
1 #pragma once
2 
3 #include <algorithm>
4 
5 #include "traits.hpp"
6 
7 namespace aaa {
8 
38 template<typename InputIterator, typename OutputIterator>
39 void negate(InputIterator first_in, InputIterator last_in, OutputIterator first_out)
40 {
41  auto f = [](const value_type_i<InputIterator>& in) { return -in; };
42  std::transform(first_in, last_in, first_out, f);
43 }
44 
45 template<typename Container1, typename Container2>
46 void negate(const Container1& in, Container2& out)
47 {
48  assert(in.size() == out.size());
49  using std::begin;
50  using std::end;
51  negate(begin(in), end(in), begin(out));
52 }
53 
54 template<typename Container>
55 Container negate(const Container& in)
56 {
57  auto out = in;
58  negate(in, out);
59  return out;
60 }
61 
64 } // namespace aaa
Definition: add.hpp:7