libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Set< T > Class Template Reference

Ordered unique-element container wrapping std::set. More...

#include <set.h>

Public Types

using Ptr = SharedPtr< Set >
 Shared pointer type for Set.
 
using Data = std::set< T >
 Underlying std::set storage type.
 
using Iterator = typename Data::iterator
 Mutable forward iterator.
 
using ConstIterator = typename Data::const_iterator
 Const forward iterator.
 
using RevIterator = typename Data::reverse_iterator
 Mutable reverse iterator.
 
using ConstRevIterator = typename Data::const_reverse_iterator
 Const reverse iterator.
 

Public Member Functions

 Set ()=default
 Default constructor. Creates an empty set.
 
 Set (const Set &other)
 Copy constructor.
 
 Set (Set &&other) noexcept
 Move constructor.
 
 Set (std::initializer_list< T > initList)
 Constructs a set from an initializer list.
 
 ~Set ()=default
 Destructor.
 
Setoperator= (const Set &other)
 Copy assignment operator.
 
Setoperator= (Set &&other) noexcept
 Move assignment operator.
 
Iterator begin () noexcept
 Returns a mutable iterator to the first element.
 
ConstIterator begin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator cbegin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator constBegin () const noexcept
 Returns a const iterator to the first element.
 
Iterator end () noexcept
 Returns a mutable iterator to one past the last element.
 
ConstIterator end () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator cend () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator constEnd () const noexcept
 Returns a const iterator to one past the last element.
 
RevIterator rbegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
RevIterator revBegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
ConstRevIterator crbegin () const noexcept
 Returns a const reverse iterator to the last element.
 
ConstRevIterator constRevBegin () const noexcept
 Returns a const reverse iterator to the last element.
 
RevIterator rend () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
RevIterator revEnd () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
ConstRevIterator crend () const noexcept
 Returns a const reverse iterator to one before the first element.
 
ConstRevIterator constRevEnd () const noexcept
 Returns a const reverse iterator to one before the first element.
 
bool isEmpty () const noexcept
 Returns true if the set has no elements.
 
size_t size () const noexcept
 Returns the number of elements.
 
bool contains (const T &value) const
 Returns true if value exists in the set.
 
Iterator find (const T &value)
 Finds value in the set.
 
ConstIterator find (const T &value) const
 Const overload of find().
 
Iterator lowerBound (const T &value)
 Returns an iterator to the first element not less than value.
 
ConstIterator lowerBound (const T &value) const
 Const overload of lowerBound().
 
Iterator upperBound (const T &value)
 Returns an iterator to the first element greater than value.
 
ConstIterator upperBound (const T &value) const
 Const overload of upperBound().
 
std::pair< Iterator, boolinsert (const T &value)
 Inserts a value into the set.
 
std::pair< Iterator, boolinsert (T &&value)
 Inserts a value into the set (move overload).
 
bool remove (const T &value)
 Removes value from the set.
 
Iterator remove (Iterator pos)
 Removes the element at pos.
 
void clear () noexcept
 Removes all elements.
 
void swap (Set &other) noexcept
 Swaps contents with another set.
 
Set unite (const Set &other) const
 Returns the union of this set and other.
 
Set intersect (const Set &other) const
 Returns the intersection of this set and other.
 
Set subtract (const Set &other) const
 Returns this set minus other.
 
List< TtoList () const
 Converts the set to a List.
 
template<typename Func >
void forEach (Func &&func) const
 Calls func for every element.
 

Friends

bool operator== (const Set &lhs, const Set &rhs)
 Returns true if both sets have identical contents.
 
bool operator!= (const Set &lhs, const Set &rhs)
 Returns true if the sets differ.
 

Detailed Description

template<typename T>
class Set< T >

Ordered unique-element container wrapping std::set.

Provides a Qt-inspired API over std::set with consistent naming conventions matching the rest of libpromeki.

Example
Set<String> tags = {"alpha", "beta"};
tags.insert("gamma");
bool has = tags.contains("alpha"); // true
tags.remove("beta");
Dynamic array container wrapping std::vector.
Definition list.h:40
bool contains(const T &val) const
Returns true if the list contains the given value.
Definition list.h:593
Iterator remove(ConstIterator pos)
Removes the element at the given iterator position.
Definition list.h:402
Iterator insert(ConstIterator pos, const T &value)
Inserts a value before the position given by an iterator.
Definition list.h:341
PROMEKI_NAMESPACE_BEGIN Container sorted(Container c)
Returns a sorted copy of the container.
Definition algorithm.h:27
Template Parameters
TElement type (must support operator<).

Constructor & Destructor Documentation

◆ Set()

template<typename T >
Set< T >::Set ( std::initializer_list< T initList)
inline

Constructs a set from an initializer list.

Parameters
initListBrace-enclosed list of values.

Member Function Documentation

◆ constBegin()

template<typename T >
ConstIterator Set< T >::constBegin ( ) const
inlinenoexcept

Returns a const iterator to the first element.

◆ constEnd()

template<typename T >
ConstIterator Set< T >::constEnd ( ) const
inlinenoexcept

Returns a const iterator to one past the last element.

◆ constRevBegin()

template<typename T >
ConstRevIterator Set< T >::constRevBegin ( ) const
inlinenoexcept

Returns a const reverse iterator to the last element.

◆ constRevEnd()

template<typename T >
ConstRevIterator Set< T >::constRevEnd ( ) const
inlinenoexcept

Returns a const reverse iterator to one before the first element.

◆ find()

template<typename T >
Iterator Set< T >::find ( const T value)
inline

Finds value in the set.

Parameters
valueThe value to search for.
Returns
Iterator to the element, or end() if not found.

◆ forEach()

template<typename T >
template<typename Func >
void Set< T >::forEach ( Func &&  func) const
inline

Calls func for every element.

Template Parameters
FuncCallable with signature void(const T &).
Parameters
funcThe function to invoke.

◆ insert() [1/2]

template<typename T >
std::pair< Iterator, bool > Set< T >::insert ( const T value)
inline

Inserts a value into the set.

Parameters
valueThe value to insert.
Returns
A pair of iterator and bool. The bool is true if insertion took place, false if the element already existed.

◆ insert() [2/2]

template<typename T >
std::pair< Iterator, bool > Set< T >::insert ( T &&  value)
inline

Inserts a value into the set (move overload).

Parameters
valueThe value to insert (moved).
Returns
A pair of iterator and bool.

◆ intersect()

template<typename T >
Set Set< T >::intersect ( const Set< T > &  other) const
inline

Returns the intersection of this set and other.

Parameters
otherThe set to intersect with.
Returns
A new Set containing only elements present in both sets.

◆ lowerBound()

template<typename T >
Iterator Set< T >::lowerBound ( const T value)
inline

Returns an iterator to the first element not less than value.

Parameters
valueThe value to search for.
Returns
Iterator to the lower bound.

◆ remove() [1/2]

template<typename T >
bool Set< T >::remove ( const T value)
inline

Removes value from the set.

Parameters
valueThe value to remove.
Returns
True if the element was removed, false if not found.

◆ remove() [2/2]

template<typename T >
Iterator Set< T >::remove ( Iterator  pos)
inline

Removes the element at pos.

Parameters
posIterator to the element to remove.
Returns
Iterator to the next element.

◆ revBegin()

template<typename T >
RevIterator Set< T >::revBegin ( )
inlinenoexcept

Returns a mutable reverse iterator to the last element.

◆ revEnd()

template<typename T >
RevIterator Set< T >::revEnd ( )
inlinenoexcept

Returns a mutable reverse iterator to one before the first element.

◆ subtract()

template<typename T >
Set Set< T >::subtract ( const Set< T > &  other) const
inline

Returns this set minus other.

Parameters
otherThe set to subtract.
Returns
A new Set containing elements in this set but not in other.

◆ swap()

template<typename T >
void Set< T >::swap ( Set< T > &  other)
inlinenoexcept

Swaps contents with another set.

Parameters
otherThe set to swap with.

◆ toList()

template<typename T >
List< T > Set< T >::toList ( ) const
inline

Converts the set to a List.

Returns
A List containing all elements in sorted order.

◆ unite()

template<typename T >
Set Set< T >::unite ( const Set< T > &  other) const
inline

Returns the union of this set and other.

Parameters
otherThe set to unite with.
Returns
A new Set containing all elements from both sets.

◆ upperBound()

template<typename T >
Iterator Set< T >::upperBound ( const T value)
inline

Returns an iterator to the first element greater than value.

Parameters
valueThe value to search for.
Returns
Iterator to the upper bound.

The documentation for this class was generated from the following file: