aboutsummaryrefslogtreecommitdiff
path: root/src/util/concepts.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/concepts.hpp')
-rw-r--r--src/util/concepts.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/util/concepts.hpp b/src/util/concepts.hpp
new file mode 100644
index 0000000..928ee39
--- /dev/null
+++ b/src/util/concepts.hpp
@@ -0,0 +1,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);
+};