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>
56 else {
return std::as_const(member); }
83 if constexpr ((std::is_same_v<T, Ts> || ...))
90 int &get() {
return index; }
93 if (index >= 0) { member = list[index]; }
96 return Memo { -1, member,
static_cast<const CSequence<T> &
>(*this) };
98 else {
return std::ref(member); }
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.
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...
CSequence< T > & getTable()
Return reference to the flat list T table.
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.