94 lines
3.2 KiB
C++
94 lines
3.2 KiB
C++
#pragma once
|
|
|
|
#include "dtcore/inc/dtvector.h"
|
|
#include "dtcore/inc/dtcontainer.h"
|
|
#include "dtcore/inc/dtmath.h"
|
|
#include "dtcore/inc/dterror.h"
|
|
|
|
#pragma warning(push)
|
|
#include <set>
|
|
#include <iterator>
|
|
#pragma warning(pop)
|
|
|
|
namespace dt
|
|
{
|
|
|
|
template <class KEY, class LESS = std::less<KEY>,
|
|
class ALLOCATOR = StdContainerAllocator<KEY>> class Set
|
|
: private std::set<KEY, LESS, ALLOCATOR>
|
|
{
|
|
public:
|
|
typedef typename std::set<KEY, LESS, ALLOCATOR> MyBase;
|
|
typedef typename MyBase::reference Reference;
|
|
typedef typename MyBase::const_reference ConstReference;
|
|
typedef typename MyBase::iterator Iterator;
|
|
typedef typename MyBase::const_iterator ConstIterator;
|
|
typedef typename MyBase::reverse_iterator ReverseIterator;
|
|
typedef typename MyBase::const_reverse_iterator ConstReverseIterator;
|
|
|
|
Set() = default;
|
|
Set(const Set& rhs) : MyBase::set(rhs) {}
|
|
Set(Set&& rhs) : MyBase::set(rhs) {}
|
|
Set(const std::initializer_list<KEY>& rhs) : MyBase::set(rhs) {}
|
|
Set& operator=(const Set& rhs) { MyBase::operator =(rhs); return *this; }
|
|
Set& operator=(Set&& rhs) { MyBase::operator =(rhs); return *this; }
|
|
|
|
bool operator==(const Set& rhs) const { return std::operator==(*this, rhs); }
|
|
bool operator!=(const Set& rhs) const { return std::operator!=(*this, rhs); }
|
|
|
|
Vector<KEY> GetKeys() const;
|
|
|
|
void Merge(const Set& rhs);
|
|
void Swap(Set& rhs) { MyBase::swap(rhs); }
|
|
|
|
std::pair<Iterator, bool> Insert(const KEY& key) { return MyBase::insert(key); }
|
|
ConstIterator Find(const KEY& key) const { return MyBase::find(key); }
|
|
Iterator Find(const KEY& key) { return MyBase::find(key); }
|
|
bool Contains(const KEY& key) const { return MyBase::find(key) != end(); }
|
|
|
|
Iterator Erase(const ConstIterator& rhs);
|
|
void Clear() { MyBase::clear(); }
|
|
|
|
Iterator Begin() { return MyBase::begin(); }
|
|
ConstIterator Begin() const { return MyBase::begin(); }
|
|
Iterator begin() { return MyBase::begin(); }
|
|
ConstIterator begin() const { return MyBase::begin(); }
|
|
|
|
Iterator End() { return MyBase::end(); }
|
|
ConstIterator End() const { return MyBase::end(); }
|
|
Iterator end() { return MyBase::end(); }
|
|
ConstIterator end() const { return MyBase::end(); }
|
|
|
|
SizeT Size() const { return static_cast<SizeT>(MyBase::size()); }
|
|
bool Empty() const { return MyBase::empty(); }
|
|
|
|
};
|
|
|
|
template <class KEY, class LESS, class ALLOCATOR> inline
|
|
Vector<KEY> Set<KEY, LESS, ALLOCATOR>::GetKeys() const
|
|
{
|
|
Vector<KEY> result;
|
|
result.Reserve(Size());
|
|
for (const auto& v : *this)
|
|
{
|
|
result.PushBack(v);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
template <class KEY, class LESS, class ALLOCATOR> inline
|
|
void Set<KEY, LESS, ALLOCATOR>::Merge(const Set& rhs)
|
|
{
|
|
for (const auto& v : rhs)
|
|
{
|
|
Insert(v);
|
|
}
|
|
}
|
|
|
|
template<class KEY, class LESS, class ALLOCATOR> inline
|
|
typename Set<KEY, LESS, ALLOCATOR>::Iterator Set<KEY, LESS, ALLOCATOR>::Erase(const ConstIterator& rhs)
|
|
{
|
|
return rhs == End() ? End() : MyBase::erase(rhs);
|
|
}
|
|
|
|
}
|