Auxiliary Arithmetic Algorithms
std_algorithms_container.hpp
1 #pragma once
2 
3 #include <algorithm>
4 #include <cassert>
5 
6 #include "traits.hpp"
7 
8 namespace aaa {
9 
21 // TODO: add all_of, any_of, none_of.
22 
23 template<typename Container1, typename Container2>
24 void copy(const Container1& in, Container2& out)
25 {
26  assert(in.size() == out.size());
27  using std::begin;
28  using std::end;
29  std::copy(begin(in), end(in), begin(out));
30 }
31 
32 template<typename Container, typename Value>
33 void fill(Container& container, const Value& value)
34 {
35  using std::begin;
36  using std::end;
37  std::fill(begin(container), end(container), value);
38 }
39 
40 template<typename Container>
41 typename Container::iterator min_element(Container& container)
42 {
43  using std::begin;
44  using std::end;
45  return std::min_element(begin(container), end(container));
46 }
47 
48 template<typename Container>
49 typename Container::const_iterator min_element(const Container& container)
50 {
51  using std::begin;
52  using std::end;
53  return std::min_element(begin(container), end(container));
54 }
55 
56 template<typename Container, typename Compare>
57 typename Container::iterator min_element(Container& container, Compare comp)
58 {
59  using std::begin;
60  using std::end;
61  return std::min_element(begin(container), end(container), comp);
62 }
63 
64 template<typename Container, typename Compare>
65 typename Container::const_iterator min_element(const Container& container, Compare comp)
66 {
67  using std::begin;
68  using std::end;
69  return std::min_element(begin(container), end(container), comp);
70 }
71 
72 template<typename Container>
73 typename Container::iterator max_element(Container& container)
74 {
75  using std::begin;
76  using std::end;
77  return std::max_element(begin(container), end(container));
78 }
79 
80 template<typename Container>
81 typename Container::const_iterator max_element(const Container& container)
82 {
83  using std::begin;
84  using std::end;
85  return std::max_element(begin(container), end(container));
86 }
87 
88 
89 template<typename Container, typename Compare>
90 typename Container::iterator max_element(Container& container, Compare comp)
91 {
92  using std::begin;
93  using std::end;
94  return std::max_element(begin(container), end(container), comp);
95 }
96 
97 template<typename Container, typename Compare>
98 typename Container::const_iterator max_element(const Container& container, Compare comp)
99 {
100  using std::begin;
101  using std::end;
102  return std::max_element(begin(container), end(container), comp);
103 }
104 
105 template<typename Container>
106 std::pair<const_iterator<Container>, const_iterator<Container>>
107 minmax_element(const Container& container)
108 {
109  using std::begin;
110  using std::end;
111  return std::minmax_element(begin(container), end(container));
112 }
113 
114 template<typename Container>
115 std::pair<iterator<Container>, iterator<Container>>
116 minmax_element(Container& container)
117 {
118  using std::begin;
119  using std::end;
120  return std::minmax_element(begin(container), end(container));
121 }
122 
123 template<typename Container, typename Compare>
124 std::pair<const_iterator<Container>, const_iterator<Container>>
125 minmax_element(const Container& container, Compare comp)
126 {
127  using std::begin;
128  using std::end;
129  return std::minmax_element(begin(container), end(container), comp);
130 }
131 
132 template<typename Container, typename Compare>
133 std::pair<iterator<Container>, iterator<Container>>
134 minmax_element(Container& container, Compare comp)
135 {
136  using std::begin;
137  using std::end;
138  return std::minmax_element(begin(container), end(container), comp);
139 }
140 
143 } // namespace aaa
Definition: add.hpp:7