Flow 1.0.0
Flow project: Full implementation reference.
traits.hpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19#pragma once
20
22#include <boost/unordered/unordered_set.hpp>
23
24namespace flow::util
25{
26
27/* Normally Container_traits would have all been forward-declared in a _fwd.hpp and defined here; instead it is
28 * defined here, and that's it. This is in accordance with the list of known reasonable exceptions to
29 * the _fwd.hpp pattern; namely since Container_traits is a bunch of sizeof=0 types storing constants only. */
30
31/**
32 * Properties of various container types. For example,
33 * `"Container_traits<std::vector>::S_CHANGE_INVALIDATES_ITERATORS == true"`, while
34 * `"Container_traits<std::list>::S_CHANGE_INVALIDATES_ITERATORS == false"`.
35 * The template defines the interface, then the specializations for various container types define
36 * the implementations.
37 *
38 * @tparam Container
39 * The container type being described.
40 */
41template<typename Container>
43{
44public:
45 // Constants.
46
47 /**
48 * If false, a change (erasure, addition of an element) in the `Container` will invalidate NO
49 * iterator to that `Container`, previously obtained, except for potentially any iterator to the
50 * element being erased (if applicable).
51 */
52 static constexpr bool S_CHANGE_INVALIDATES_ITERATORS = false;
53 /// `true` if and only if iterating over the elements of a `Container` yields them in sorted order.
54 static constexpr bool S_SORTED = false;
55 /// `true` if and only if finding an element of `Container` by key takes at most constant amortized time.
56 static constexpr bool S_CONSTANT_TIME_SEARCH = false;
57 /// `true` if and only if adding an element to a `Container` (anywhere) takes at most constant amortized time.
58 static constexpr bool S_CONSTANT_TIME_INSERT = false;
59private:
60 // Constructors/destructor.
61
62 /// Forbid all instantion.
63 Container_traits() = delete;
64}; // class Container_traits<>
65
66/**
67 * Traits of `std::set`.
68 *
69 * @tparam T
70 * Type of set element.
71 */
72template<typename T>
73class Container_traits<std::set<T>>
74{
75public:
76 // Constants.
77
78 /// See Container_traits.
79 static constexpr bool S_CHANGE_INVALIDATES_ITERATORS = false;
80 /// See Container_traits.
81 static constexpr bool S_SORTED = true;
82 /// See Container_traits.
83 static constexpr bool S_CONSTANT_TIME_SEARCH = false;
84 /// See Container_traits.
85 static constexpr bool S_CONSTANT_TIME_INSERT = false;
86private:
87 // Constructors/destructor.
88
89 /// Forbid all instantion.
90 Container_traits() = delete;
91}; // class Container_traits<std::set>
92
93/**
94 * Traits of `std::map`.
95 *
96 * @tparam K
97 * Type of map key element.
98 * @tparam V
99 * Type of map value element.
100 */
101template<typename K, typename V>
102class Container_traits<std::map<K, V>>
103{
104public:
105 // Constants.
106
107 /// See Container_traits.
108 static constexpr bool S_CHANGE_INVALIDATES_ITERATORS = false;
109 /// See Container_traits.
110 static constexpr bool S_SORTED = true;
111 /// See Container_traits.
112 static constexpr bool S_CONSTANT_TIME_SEARCH = false;
113 /// See Container_traits.
114 static constexpr bool S_CONSTANT_TIME_INSERT = false;
115private:
116 // Constructors/destructor.
117
118 /// Forbid all instantion.
120}; // class Container_traits<std::map>
121
122/**
123 * Traits of `boost::unordered_set`.
124 *
125 * @tparam T
126 * Type of set element.
127 */
128template<typename T>
129class Container_traits<boost::unordered_set<T>>
130{
131public:
132 // Constants.
133
134 /// See Container_traits.
135 static constexpr bool S_CHANGE_INVALIDATES_ITERATORS = true;
136 /// See Container_traits.
137 static constexpr bool S_SORTED = false;
138 /// See Container_traits.
139 static constexpr bool S_CONSTANT_TIME_SEARCH = true;
140 /// See Container_traits.
141 static constexpr bool S_CONSTANT_TIME_INSERT = true;
142private:
143 // Constructors/destructor.
144
145 /// Forbid all instantion.
147}; // class Container_traits<boost::unordered_set>
148
149/**
150 * Traits of flow::util::Linked_hash_map.
151 *
152 * @tparam K
153 * Type of map key element.
154 * @tparam V
155 * Type of map value element.
156 */
157template<typename K, typename V>
159{
160public:
161 // Constants.
162
163 /// See Container_traits.
164 static constexpr bool S_CHANGE_INVALIDATES_ITERATORS = false;
165 /// See Container_traits.
166 static constexpr bool S_SORTED = false;
167 /// See Container_traits.
168 static constexpr bool S_CONSTANT_TIME_SEARCH = true;
169 /// See Container_traits.
170 static constexpr bool S_CONSTANT_TIME_INSERT = true;
171private:
172 // Constructors/destructor.
173
174 /// Forbid all instantion.
176}; // class Container_traits<util::Linked_hash_map>
177
178/**
179 * Traits of flow::util::Linked_hash_set.
180 *
181 * @tparam T
182 * Type of set element.
183 * @tparam Hash
184 * Hasher.
185 * @tparam Pred
186 * Equality predicate.
187 */
188template<typename T, typename Hash, typename Pred>
189class Container_traits<util::Linked_hash_set<T, Hash, Pred>>
190{
191public:
192 // Constants.
193
194 /// See Container_traits.
195 static constexpr bool S_CHANGE_INVALIDATES_ITERATORS = false;
196 /// See Container_traits.
197 static constexpr bool S_SORTED = false;
198 /// See Container_traits.
199 static constexpr bool S_CONSTANT_TIME_SEARCH = true;
200 /// See Container_traits.
201 static constexpr bool S_CONSTANT_TIME_INSERT = true;
202private:
203 // Constructors/destructor.
204
205 /// Forbid all instantion.
207}; // class Container_traits<util::Linked_hash_set>
208
209} // namespace flow::util
Container_traits()=delete
Forbid all instantion.
Container_traits()=delete
Forbid all instantion.
Properties of various container types.
Definition: traits.hpp:43
static constexpr bool S_CHANGE_INVALIDATES_ITERATORS
If false, a change (erasure, addition of an element) in the Container will invalidate NO iterator to ...
Definition: traits.hpp:52
static constexpr bool S_SORTED
true if and only if iterating over the elements of a Container yields them in sorted order.
Definition: traits.hpp:54
Container_traits()=delete
Forbid all instantion.
static constexpr bool S_CONSTANT_TIME_SEARCH
true if and only if finding an element of Container by key takes at most constant amortized time.
Definition: traits.hpp:56
static constexpr bool S_CONSTANT_TIME_INSERT
true if and only if adding an element to a Container (anywhere) takes at most constant amortized time...
Definition: traits.hpp:58
An object of this class is a map that combines the lookup speed of a boost::unordered_map<> and order...
An object of this class is a set that combines the lookup speed of an unordered_set<> and ordering an...
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
Definition: basic_blob.hpp:29