slang::Bag class

Bag - A general container of arbitrary objects.

The Bag container is a collection of various type-erased objects that can be looked up by their original type. This is useful for things like passing around a collection of various options to different subsystems without needing to have cross dependencies between them.

Public functions

template<typename T>
void set(const T& item)
template<typename T>
void set(T&& item)
template<typename T>
auto get() const -> const T*
template<typename T>
auto getOrDefault() const -> T

Function documentation

template<typename T>
void slang::Bag::set(const T& item)

Adds or overwrites an existing element of type T in the bag (making a copy in the process).

template<typename T>
void slang::Bag::set(T&& item)

Adds or overwrites an existing element of type T in the bag (moving in the new item in the process).

template<typename T>
const T* slang::Bag::get() const

Gets an element of type T from the bag, if it exists. Otherwise returns nullptr.

template<typename T>
T slang::Bag::getOrDefault() const

Gets an element of type T from the bag, if it exists. Otherwise returns a default constructed T.