This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
BWMirror-Generator/bwapi4-includes/BWAPI/SetContainer.h

53 lines
1.6 KiB
C
Raw Normal View History

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 >;
/// This container is used to wrap convenience functions for BWAPI and be used as a bridge with
/// a built-in set type.
///
/// @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) {}
/// Iterates the set and erases each element x where pred(x) returns true.
///
/// @param pred
/// Predicate for removing elements.
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;
}
};
/// Checks if this set contains a specific value.
///
/// @param value
/// Value to search for.
bool contains(T const &value) const
{
return count(value) != 0;
}
};
}