aboutsummaryrefslogtreecommitdiff
path: root/src/util/concepts.hpp
blob: 928ee397df6c025a1270f596121848663bf6d48b (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once

#include <concepts>
#include <iterator>

/**
 * Concept for the Container named requirement.
 *
 * https://en.cppreference.com/w/cpp/named_req/Container
 */
template <class ContainerType>
concept Container = requires(ContainerType container_a, const ContainerType container_b)
{
	typename ContainerType::value_type;
	typename ContainerType::reference;
	typename ContainerType::const_reference;
	typename ContainerType::iterator;
	typename ContainerType::const_iterator;
	typename ContainerType::difference_type;
	typename ContainerType::size_type;

	requires std::regular<ContainerType>;
	requires std::swappable<ContainerType>;
	requires std::destructible<typename ContainerType::value_type>;
	requires std::
		same_as<typename ContainerType::reference, typename ContainerType::value_type &>;
	requires std::same_as<
		typename ContainerType::const_reference,
		const typename ContainerType::value_type &>;
	requires std::forward_iterator<typename ContainerType::iterator>;
	requires std::forward_iterator<typename ContainerType::const_iterator>;
	requires std::signed_integral<typename ContainerType::difference_type>;
	requires std::same_as<
		typename ContainerType::difference_type,
		typename std::iterator_traits<typename ContainerType::iterator>::difference_type>;
	requires std::same_as<
		typename ContainerType::difference_type,
		typename std::iterator_traits<
			typename ContainerType::const_iterator>::difference_type>;
	requires std::convertible_to<
		typename ContainerType::iterator,
		typename ContainerType::const_iterator>;

	{
		container_a.begin()
		} -> std::same_as<typename ContainerType::iterator>;
	{
		container_a.end()
		} -> std::same_as<typename ContainerType::iterator>;
	{
		container_b.begin()
		} -> std::same_as<typename ContainerType::const_iterator>;
	{
		container_b.end()
		} -> std::same_as<typename ContainerType::const_iterator>;
	{
		container_a.cbegin()
		} -> std::same_as<typename ContainerType::const_iterator>;
	{
		container_a.cend()
		} -> std::same_as<typename ContainerType::const_iterator>;
	{
		container_a.size()
		} -> std::same_as<typename ContainerType::size_type>;
	{
		container_a.max_size()
		} -> std::same_as<typename ContainerType::size_type>;
	{
		container_a.empty()
		} -> std::same_as<bool>;
};

template <typename ContainerType>
concept HasPushBack =
	requires(ContainerType container, typename ContainerType::value_type value)
{
	container.push_back(value);
};