9 #ifndef CPROVER_UTIL_FORWARD_LIST_AS_MAP_H
10 #define CPROVER_UTIL_FORWARD_LIST_AS_MAP_H
13 #include <forward_list>
19 template <
typename keyt,
typename mappedt>
26 using iterator =
typename implementationt::iterator;
41 if(it != this->end() && it->first == name)
43 iterator before = this->before_begin();
44 while(std::next(before) != it)
46 this->erase_after(before);
54 if(it == this->end() || it->first != name)
64 if(it == this->end() || it->first != name)
66 iterator before = this->before_begin();
67 while(std::next(before) != it)
69 it = this->emplace_after(before, name, mappedt());
77 return add(name)->second;
80 mappedt &
add(
const keyt &name, mappedt irep)
84 if(it == this->end() || it->first != name)
86 iterator before = this->before_begin();
87 while(std::next(before) != it)
89 it = this->emplace_after(before, name, std::move(irep));
92 it->second = std::move(irep);
97 mappedt &
emplace(
const keyt &name,
const mappedt &irep)
101 if(it == this->end() || it->first != name)
103 iterator before = this->before_begin();
104 while(std::next(before) != it)
106 it = this->emplace_after(before, name, irep);
116 return narrow<std::size_t>(std::distance(this->begin(), this->end()));
120 static bool order(
const std::pair<keyt, mappedt> &a,
const keyt &b)
127 return std::lower_bound(this->begin(), this->end(),
id,
order);
132 return std::lower_bound(this->begin(), this->end(),
id,
order);
Implementation of map-like interface using a forward list.
const const_iterator find(const keyt &name) const
iterator mutable_lower_bound(const keyt &id)
forward_list_as_mapt(std::initializer_list< std::pair< keyt, mappedt >> list)
typename std::forward_list< std::pair< keyt, mappedt > > implementationt
typename implementationt::iterator iterator
mappedt & add(const keyt &name, mappedt irep)
iterator add(const keyt &name)
void erase(const keyt &name)
mappedt & emplace(const keyt &name, const mappedt &irep)
const_iterator lower_bound(const keyt &id) const
typename implementationt::const_iterator const_iterator
mappedt & operator[](const keyt &name)
static bool order(const std::pair< keyt, mappedt > &a, const keyt &b)