-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathbase_collections.h
138 lines (111 loc) · 2.86 KB
/
base_collections.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
namespace winrt::impl
{
namespace wfc = Windows::Foundation::Collections;
template <typename D, typename T>
auto consume_Windows_Foundation_Collections_IIterable<D, T>::begin() const
{
return get_begin_iterator(static_cast<D const&>(*this));
}
template <typename D, typename T>
auto consume_Windows_Foundation_Collections_IIterable<D, T>::end() const
{
return get_end_iterator(static_cast<D const&>(*this));
}
template <typename T>
struct key_value_pair;
template <typename K, typename V>
struct key_value_pair<wfc::IKeyValuePair<K, V>> : implements<key_value_pair<wfc::IKeyValuePair<K, V>>, wfc::IKeyValuePair<K, V>>
{
key_value_pair(K key, V value) :
m_key(std::move(key)),
m_value(std::move(value))
{
}
K Key() const
{
return m_key;
}
V Value() const
{
return m_value;
}
private:
K const m_key;
V const m_value;
};
template <typename T>
struct is_key_value_pair : std::false_type {};
template <typename K, typename V>
struct is_key_value_pair<wfc::IKeyValuePair<K, V>> : std::true_type {};
struct input_scope
{
void invalidate_scope() noexcept
{
m_invalid = true;
}
void check_scope() const
{
if (m_invalid)
{
throw hresult_illegal_method_call();
}
}
private:
bool m_invalid{};
};
struct no_collection_version
{
struct iterator_type
{
iterator_type(no_collection_version const&) noexcept
{
}
void check_version(no_collection_version const&) const noexcept
{
}
};
};
struct collection_version
{
struct iterator_type
{
iterator_type(collection_version const& version) noexcept :
m_snapshot(version.get_version())
{
}
void check_version(collection_version const& version) const
{
if (version.get_version() != m_snapshot)
{
throw hresult_changed_state();
}
}
private:
uint32_t const m_snapshot;
};
uint32_t get_version() const noexcept
{
return m_version;
}
void increment_version() noexcept
{
++m_version;
}
private:
std::atomic<uint32_t> m_version{};
};
template <typename T>
struct range_container
{
T const first;
T const last;
auto begin() const noexcept
{
return first;
}
auto end() const noexcept
{
return last;
}
};
}