25 #ifndef INCLUDED_PassthruUniqueContainer_h_GUID_AD5E86CA_230D_4BBA_8DF0_F2C3811CFD00
26 #define INCLUDED_PassthruUniqueContainer_h_GUID_AD5E86CA_230D_4BBA_8DF0_F2C3811CFD00
41 namespace unique_container_policies {
51 using iterator =
typename Container::iterator;
52 using const_iterator =
typename Container::const_iterator;
53 using value_type =
typename Container::value_type;
54 using reference =
typename Container::reference;
55 using rv_reference =
typename Container::value_type &&;
56 using const_reference =
typename Container::const_reference;
58 static bool contains(Container
const &c, const_reference v) {
64 static bool remove(Container &c, const_reference v) {
76 static bool insert(Container &c, const_reference v) {
87 static bool insert(Container &c, rv_reference v) {
96 static auto find(Container
const &c, const_reference v)
97 -> decltype(std::find(begin(c), end(c), v)) {
98 return std::find(begin(c), end(c), v);
102 static auto find(Container &c, const_reference v)
103 -> decltype(std::find(begin(c), end(c), v)) {
104 return std::find(begin(c), end(c), v);
119 template <
template <
class X>
class Comparison = std::less>
123 using iterator =
typename Container::iterator;
124 using const_iterator =
typename Container::const_iterator;
125 using value_type =
typename Container::value_type;
126 using reference =
typename Container::reference;
127 using rv_reference =
typename Container::value_type &&;
128 using const_reference =
typename Container::const_reference;
129 using comparator = Comparison<value_type>;
140 -> decltype(std::lower_bound(begin(c), end(c), v,
142 return std::lower_bound(begin(c), end(c), v,
152 -> decltype(std::lower_bound(begin(c), end(c), v,
154 return std::lower_bound(begin(c), end(c), v,
160 static bool contains(Container
const &c, const_reference v) {
161 return std::binary_search(begin(c), end(c), v,
168 static bool remove(Container &c, const_reference v) {
182 static bool insert(Container &c, const_reference v) {
196 static bool insert(Container &c, rv_reference v) {
209 static auto find(Container
const &c, const_reference v)
220 static auto find(Container &c, const_reference v)
232 return !(comp(a, b)) && !(comp(b, a));
238 template <
typename IteratorType>
240 IteratorType
const &it,
249 static void sort(Container &c) {
255 struct SortedInsert {
256 template <
typename Container>
257 using Specialized = SortedInsertCustomCompare<
258 std::less>::template Specialized<Container>;
286 template <
typename Container,
287 typename Policy = unique_container_policies::PushBack,
288 typename... WrapperArgs>
291 typedef typename Policy::template Specialized<Container> policy;
295 using value_type =
typename Container::value_type;
296 using reference =
typename Container::reference;
297 using rv_reference =
typename Container::value_type &&;
298 using const_reference =
typename Container::const_reference;
304 bool insert(const_reference v) {
307 bool insert(rv_reference v) {
return policy::insert(
container(), v); }
308 bool remove(const_reference v) {
313 Container
const &
container()
const {
return base::container(); }
318 Container &
container() {
return base::container(); }
324 template <
typename Container,
325 typename Policy = unique_container_policies::PushBack,
326 typename... WrapperArgs>
332 using rv_reference =
typename Container::value_type &&;
333 using const_reference =
typename Container::const_reference;
335 bool insert(const_reference v) {
return base::insert(v); }
336 bool insert(rv_reference v) {
return base::insert(v); }
337 bool remove(const_reference v) {
return base::remove(v); }
345 #endif // INCLUDED_PassthruUniqueContainer_h_GUID_AD5E86CA_230D_4BBA_8DF0_F2C3811CFD00
static auto find(Container const &c, const_reference v) -> decltype(policy::lower_bound(c, v))
Helper function. Time complexity: O(std::lower_bound) = O(lg n) Based on lower_bound with an addition...
static bool insert(Container &c, const_reference v)
Insert from a const reference. Time complexity: O(contains) + O(member push_back), which is O(n) (+ amortized constant time) for a std::vector.
static bool contains(Container const &c, const_reference v)
Part of the interface expected by UniqueContainer. Time complexity: O(std::binary_search) = O(lg n) ...
apply_list< quote< or_ >, transform< Haystack, detail::is_< Needle >>> contains
Determines if type Needle is in the list Haystack - is an alias for a type that inherits std::true_ty...
static auto lower_bound(Container const &c, const_reference v) -> decltype(std::lower_bound(begin(c), end(c), v, policy::get_comparator()))
Helper function. Wraps both the range aspects and the comparator for easier use of the underlying std...
static void sort(Container &c)
Helper function.
static bool check_equiv(const_reference a, const_reference b)
Helper function. !(A < B) && !(B < A) is used to imply A == B O(1) comparisons performed.
Header providing a class template suitable for inheritance that wraps an arbitrary STL-like container...
A basic policy for use with a vector or similar container, where you have a comparison operator and t...
A basic policy for use with a vector or similar container, where you don't expect a lot of additions ...
static bool insert(Container &c, const_reference v)
Part of the interface expected by UniqueContainer. Insert from a const reference. Time complexity: O(...
static bool iter_indicates_contains(Container const &c, IteratorType const &it, const_reference v)
Helper function. Look at an iterator, for instance, from lower_bound, and determine if it implies the...
static auto lower_bound(Container &c, const_reference v) -> decltype(std::lower_bound(begin(c), end(c), v, policy::get_comparator()))
Helper function. Wraps both the range aspects and the comparator for easier use of the underlying std...
static auto find(Container &c, const_reference v) -> decltype(std::find(begin(c), end(c), v))
Time complexity: O(std::find) = O(n)
static bool insert(Container &c, rv_reference v)
Part of the interface expected by UniqueContainer. Insert from an rvalue-reference (move-insert)...
bool contains(const_reference v)
Returns true iff the underlying container contains an instance of the given value.
static bool contains(Container const &c, const_reference v)
Time complexity: O(find) = O(n)
Container const & container() const
Const access to the container is permitted.
static comparator get_comparator()
Helper function to avoid vexing parse.
static auto find(Container &c, const_reference v) -> decltype(policy::lower_bound(c, v))
Helper function. Time complexity: O(std::lower_bound) = O(lg n) Based on lower_bound with an addition...
detail::ContainerWrapper_t< Container, Args...> ContainerWrapper
Parent class to inherit from to get a container with some functionality exposed.
static auto find(Container const &c, const_reference v) -> decltype(std::find(begin(c), end(c), v))
Time complexity: O(std::find) = O(n)
Container const & container() const
Const access to the container is permitted.
A "Unique Container" designed for composition, not inheritance.
A policy-based generic "Unique Container", that wraps ContainerWrapper (and thus an underlying contai...
static bool insert(Container &c, rv_reference v)
Insert from an rvalue-reference (move-insert). Time complexity: O(contains) + O(member emplace_back)...