2015-02-07 12:16:07 -05:00
|
|
|
#pragma once
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace BWAPI
|
|
|
|
{
|
|
|
|
template <class T, class HashT>
|
|
|
|
using SetContainerUnderlyingT = std::unordered_set < T, HashT >;
|
|
|
|
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>This container is used to wrap convenience functions for BWAPI and be used as a
|
|
|
|
/// bridge with a built-in set type.</summary>
|
2015-02-07 12:16:07 -05:00
|
|
|
///
|
|
|
|
/// @tparam T
|
|
|
|
/// Type that this set contains.
|
|
|
|
/// @tparam HashT
|
|
|
|
/// Hash type. Defaults to integral hashing for BWAPI usage.
|
|
|
|
template <class T, class HashT = std::hash<int>>
|
|
|
|
class SetContainer : public SetContainerUnderlyingT < T, HashT >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SetContainer() : SetContainerUnderlyingT<T, HashT>() {}
|
|
|
|
SetContainer(SetContainer const &other) : SetContainerUnderlyingT<T, HashT>(other) {}
|
|
|
|
SetContainer(SetContainer &&other) : SetContainerUnderlyingT<T, HashT>(std::forward<SetContainer>(other)) {}
|
|
|
|
SetContainer(std::initializer_list<T> ilist) : SetContainerUnderlyingT<T, HashT>(ilist) {}
|
|
|
|
|
|
|
|
template <class IterT>
|
|
|
|
SetContainer(IterT _begin, IterT _end) : SetContainerUnderlyingT<T, HashT>(_begin, _end) {}
|
|
|
|
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>Iterates the set and erases each element x where pred(x) returns true.</summary>
|
2015-02-07 12:16:07 -05:00
|
|
|
///
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <param name="pred">
|
2015-02-07 12:16:07 -05:00
|
|
|
/// Predicate for removing elements.
|
2016-02-28 08:49:15 -05:00
|
|
|
/// </param>
|
|
|
|
/// @see std::erase_if
|
2015-02-07 12:16:07 -05:00
|
|
|
template<class Pred>
|
|
|
|
void erase_if(const Pred& pred) {
|
|
|
|
auto it = this->begin();
|
|
|
|
while (it != this->end()) {
|
|
|
|
if (pred(*it)) it = this->erase(it);
|
|
|
|
else ++it;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>Checks if this set contains a specific value.</summary>
|
2015-02-07 12:16:07 -05:00
|
|
|
///
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <param name="value">
|
2015-02-07 12:16:07 -05:00
|
|
|
/// Value to search for.
|
2016-02-28 08:49:15 -05:00
|
|
|
/// </param>
|
2015-02-07 12:16:07 -05:00
|
|
|
bool contains(T const &value) const
|
|
|
|
{
|
|
|
|
return count(value) != 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|