diff options
author | HampusM <hampus@hampusmat.com> | 2022-06-02 19:51:54 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:57:00 +0200 |
commit | eecf4b1e666211a13afa56f93477c55e8fd01621 (patch) | |
tree | 410510d6e058995174d5a5b0f535fb457a0c3542 /src/util/concepts.hpp | |
parent | 87f55120f96d0f4f80b497dc9006d89df2dda125 (diff) |
feat: implement game of lifev0.1.0
Diffstat (limited to 'src/util/concepts.hpp')
-rw-r--r-- | src/util/concepts.hpp | 78 |
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); +}; |