File: Container.h

package info (click to toggle)
edb-debugger 1.3.0-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,124 kB
  • sloc: cpp: 46,241; xml: 4,998; ansic: 3,088; sh: 52; asm: 33; makefile: 5
file content (52 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#ifndef UTIL_CONTAINER_H_2020227_
#define UTIL_CONTAINER_H_2020227_

#include <algorithm>
#include <array>
#include <type_traits>

namespace util {

template <class T, size_t N, class U = T>
constexpr void shl(std::array<T, N> &buffer, U value = T()) {
	static_assert(std::is_convertible<T, U>::value, "U must be convertable to the type contained in the array!");
	std::rotate(buffer.begin(), buffer.begin() + 1, buffer.end());
	buffer[N - 1] = value;
}

template <class T, size_t N, class U = T>
constexpr void shr(std::array<T, N> &buffer, U value = T()) {
	static_assert(std::is_convertible<T, U>::value, "U must be convertable to the type contained in the array!");
	std::rotate(buffer.rbegin(), buffer.rbegin() + 1, buffer.rend());
	buffer[0] = value;
}

template <class T, size_t N>
constexpr void rol(std::array<T, N> &buffer) {
	std::rotate(buffer.begin(), buffer.begin() + 1, buffer.end());
}

template <class T, size_t N>
constexpr void ror(std::array<T, N> &buffer) {
	std::rotate(buffer.rbegin(), buffer.rbegin() + 1, buffer.rend());
}

template <typename T, typename... Tail>
constexpr auto make_array(T head, Tail... tail) -> std::array<T, 1 + sizeof...(Tail)> {
	return std::array<T, 1 + sizeof...(Tail)>{head, tail...};
}

template <typename Container, typename Element>
bool contains(const Container &container, const Element &element) {
	return std::find(std::begin(container), std::end(container), element) != std::end(container);
}

template <typename Container, typename Pred>
bool contains_if(const Container &container, Pred pred) {
	return std::find_if(std::begin(container), std::end(container), pred) != std::end(container);
}

}

#endif