9#ifndef CPROVER_UTIL_FORWARD_LIST_AS_MAP_H
10#define CPROVER_UTIL_FORWARD_LIST_AS_MAP_H
13#include <forward_list>
19template <
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);
99 return narrow<std::size_t>(std::distance(this->begin(), this->end()));
103 static bool order(
const std::pair<keyt, mappedt> &a,
const keyt &b)
110 return std::lower_bound(this->begin(), this->end(),
id,
order);
115 return std::lower_bound(this->begin(), this->end(),
id,
order);
Implementation of map-like interface using a forward list.
void remove(const keyt &name)
const const_iterator find(const keyt &name) const
iterator mutable_lower_bound(const keyt &id)
typename std::forward_list< std::pair< keyt, mappedt > > implementationt
typename implementationt::iterator iterator
forward_list_as_mapt(std::initializer_list< std::pair< keyt, mappedt > > list)
iterator add(const keyt &name)
const_iterator lower_bound(const keyt &id) const
mappedt & operator[](const keyt &name)
mappedt & add(const keyt &name, mappedt irep)
typename implementationt::const_iterator const_iterator
static bool order(const std::pair< keyt, mappedt > &a, const keyt &b)