-
Notifications
You must be signed in to change notification settings - Fork 2
/
CSet.h
53 lines (43 loc) · 1.66 KB
/
CSet.h
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
#pragma once
#include <concepts>
#include <ranges>
#include <tuple>
#include <type_traits>
#include "CEnumerable.h"
namespace Platform::Interfaces {
namespace Internal {
template <typename TRawSelf, typename... TItems>
consteval bool CSetHelpFunction() {
using Self = std::remove_const_t<TRawSelf>;
if constexpr (sizeof...(TItems) == 1) {
return requires(Self self, std::tuple<TItems...> items, decltype(std::get<0>(items)) item) {
{ self.find(item) } -> std::same_as<std::ranges::iterator_t<Self>>;
{self.insert(item)};
{self.erase(item)};
{ self.contains(item) } -> std::same_as<bool>;
{ self.empty() } -> std::same_as<bool>;
{ self.size() } -> std::integral;
{self.clear()};
requires std::ranges::forward_range<Self>;
};
}
if constexpr (sizeof...(TItems) == 0) {
return requires(Self self, typename Enumerable<Self>::Item generic_item) {
{ self.find(generic_item) } -> std::same_as<std::ranges::iterator_t<Self>>;
{self.insert(generic_item)};
{self.erase(generic_item)};
{ self.contains(generic_item) } -> std::same_as<bool>;
{ self.empty() } -> std::same_as<bool>;
{ self.size() } -> std::integral;
{self.clear()};
requires std::ranges::forward_range<Self>;
};
}
return false;
}
} // namespace Internal
template <typename TSelf, typename... TItems>
concept CSet = CEnumerable<TSelf> && Internal::CSetHelpFunction<TSelf, TItems...>();
template <CSet TSelf>
struct Set : Enumerable<TSelf> {};
} // namespace Platform::Interfaces