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)
Adds or overwrites an existing element of type T in the bag (making a copy in the process).
template<typename T>
void 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>
auto get() const -> const T*
Gets an element of type T from the bag, if it exists.
template<typename T>
auto getOrDefault() const -> T
Gets an element of type T from the bag, if it exists.

Function documentation

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.