-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathSetContainer.h
More file actions
65 lines (59 loc) · 1.85 KB
/
Copy pathSetContainer.h
File metadata and controls
65 lines (59 loc) · 1.85 KB
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
#pragma once
#include <set>
#include <functional>
#include <algorithm>
namespace BWAPI
{
template <class T, typename Compare>
// Transparent comparators for lookups from comparables, without constructing temporary objects
using SetContainerUnderlyingT = std::set < T, Compare >;
/// <summary>This container is used to wrap convenience functions for BWAPI and be used as a
/// bridge with a built-in set type.</summary>
///
/// @tparam T
/// Type that this set contains.
/// @tparam Compare
/// Function to ensure ordering.
template <class T, typename Compare = std::less<>>
class SetContainer : public SetContainerUnderlyingT < T, Compare >
{
public:
#ifndef SWIG
using SetContainerUnderlyingT<T, Compare >::SetContainerUnderlyingT;
#endif
/// <summary>Iterates the set and erases each element x where pred(x) returns true.</summary>
///
/// <param name="pred">
/// Predicate for removing elements.
/// </param>
/// @see std::erase_if
template<class Pred>
SetContainer<T, Compare>& erase_if(Pred &&pred) {
auto it = this->begin();
while (it != this->end()) {
if (pred(*it)) it = this->erase(it);
else ++it;
}
return *this;
}
/// <summary>Iterates the set and finds the first element where pred(x) returns true.</summary>
///
/// <param name="pred">
/// Predicate for searching.
/// </param>
/// @see std::find_if
template<class Pred>
typename SetContainer<T, Compare>::iterator find_if(Pred &&pred) const {
return std::find_if(this->begin(), this->end(), pred);
}
/// <summary>Checks if this set contains a specific value.</summary>
///
/// <param name="value">
/// Value to search for.
/// </param>
bool contains(T const &value) const
{
return this->count(value) != 0;
}
};
}