6#ifndef SWIFT_MISC_MEMOTABLE_H
7#define SWIFT_MISC_MEMOTABLE_H
24 int &index = m_dict[value];
27 m_list.push_back(value);
28 index = m_list.size();
44 template <
typename... Ts>
55 if constexpr ((std::is_same_v<T, Ts> || ...))
61 return std::as_const(member);
89 if constexpr ((std::is_same_v<T, Ts> || ...))
96 int &get() {
return index; }
101 member = list[index];
105 return Memo { -1, member,
static_cast<const CSequence<T> &
>(*this) };
109 return std::ref(member);
Associative container with value semantics, chooses a sensible default implementation container type.
Memoizer for Ts. Other types are passed through.
decltype(auto) maybeMemoize(const T &member)
If T is in Ts, return the index of member in the memo table. Otherwise, return member.
const CSequence< T > & getTable() const
Return the values in the T table as a flat list.
Unmemoizer for Ts. Other types are passed through.
CSequence< T > & getTable()
Return reference to the flat list T table.
auto maybeUnmemoize(T &member) const
If T is in Ts, return proxy that will assign to member through the value at the given index in the fl...
A data memoization pattern useful for compressing JSON representations of containers.
const CSequence< T > & getTable() const
Return the values in the table as a flat list.
int getIndex(const T &value)
Return the index of a value, inserting it if it is not already in the table.
Generic sequential container with value semantics.
Free functions in swift::misc.
Helper class for memoizing members of a value object.