9template<
class Indexer,
class Key,
class Value>
14 static bool is_valid(T) {
return true; }
18 struct IsValidPred<T*> {
19 static bool is_valid(T* value) {
return value !=
nullptr; }
24 : indexer_(other.indexer_)
25 , array_(other.array_) {}
27 : indexer_(std::move(other.indexer_))
28 , array_(std::move(other.array_)) {}
31 , array_(
indexer.size(), value) {}
41 const Indexer&
indexer()
const {
return indexer_; }
42 size_t capacity()
const {
return array_.size(); }
45 assert(i !=
size_t(-1));
49 auto&
array() {
return array_; }
50 const auto&
array()
const {
return array_; }
51 Value&
array(
size_t i) {
return array_[i]; }
52 const Value&
array(
size_t i)
const {
return array_[i]; }
54 auto begin()
const {
return std::views::filter(array_, IsValidPred<Value>::is_valid).begin(); }
55 auto end()
const {
return std::views::filter(array_, IsValidPred<Value>::is_valid).end(); }
59 swap(map1.indexer_, map2.indexer_);
60 swap(map1.array_, map2.array_);
64 const Indexer& indexer_;
70template<
class Indexer,
class Key,
class Value>
72 auto i = map.indexer().index(key);
73 return i != size_t(-1) ? map.array()[i] :
nullptr;
76template<
class Indexer,
class Key,
class Value>
const Value & array(size_t i) const
Value & operator[](Key key)
IndexMap(const IndexMap &other)
IndexMap(IndexMap &&other) noexcept
const Indexer & indexer() const
const Value & operator[](Key key) const
IndexMap(const Indexer &indexer, const Value &value=Value())
IndexMap & operator=(IndexMap other) noexcept
friend void swap(IndexMap &map1, IndexMap &map2) noexcept
const auto & array() const
IndexMap(const Indexer &indexer, View< Value > array)
IndexMap(const Indexer &indexer, const I begin, const I end)
This is a thin wrapper for absl::InlinedVector<T, N, A> which is a drop-in replacement for std::vecto...
Value * find(IndexMap< Indexer, Key, Value * > &map, Key key)