NamedVector

template<typename T>
class NamedVector

Ordered, name-indexed vector: a std::vector<T> where every entry also has a unique string key.

The container behind every compute-graph Function’s named inputs and outputs (NamedVector<Value>) and type lists (NamedVector<Type>), preserving insertion order while supporting both integer indexing and lookup by name.

Public Functions

NamedVector() = default

Empty vector.

inline NamedVector(const std::vector<std::string> &keys, const std::vector<T> &values)

One entry per pair of keys and values, in order.

inline NamedVector(const std::initializer_list<std::pair<std::string, T>> &items)

One entry per (key, value) pair of items, in order.

inline NamedVector(const std::vector<std::pair<std::string, T>> &items)

One entry per (key, value) pair of items, in order.

inline const std::vector<T> &values() const

The values, in insertion order.

inline const std::unordered_map<std::string, std::size_t> &index_map() const

Map from key to its position in values.

inline std::vector<std::string> keys() const

The keys, in insertion order.

inline decltype(auto) begin()

Iterator over the values, in insertion order.

inline decltype(auto) begin() const
inline decltype(auto) rbegin()
inline decltype(auto) rbegin() const
inline decltype(auto) end()
inline decltype(auto) end() const
inline decltype(auto) rend()
inline decltype(auto) rend() const
inline decltype(auto) front()

The first value.

inline decltype(auto) front() const

The first value.

inline decltype(auto) back()

The last value.

inline decltype(auto) back() const

The last value.

inline T &at(std::size_t index)

The value at position index.

inline const T &at(std::size_t index) const

The value at position index.

inline T &at(const std::string &key)

The value keyed by key.

inline const T &at(const std::string &key) const

The value keyed by key.

inline T &operator[](std::size_t index)

The value at position index.

inline const T &operator[](std::size_t index) const

The value at position index.

inline T &operator[](const std::string &key)

The value keyed by key.

inline const T &operator[](const std::string &key) const

The value keyed by key.

inline bool empty() const

Whether the vector holds no entries.

inline std::size_t size() const

Number of entries.

inline void reserve(std::size_t capacity)

Reserve storage for capacity entries.

inline void push_back(const std::string &key, const T &value)

Append value under a new key; key must not already be present.

inline void insert_back(const NamedVector<T> &other)

Append every entry of other; its keys must not already be present.

inline NamedVector<T> sort_like(const std::unordered_map<std::string, std::size_t> &index_map) const

A copy reordered to match index_map (same keys, same key-to-position mapping as this instance’s, just reassigned).