9template<
class Indexer,
class Key,
class Value>
class IndexMap {
11 template<
class T>
struct IsValidPred {
12 static bool is_valid(T) {
return true; }
15 template<
class T>
struct IsValidPred<T*> {
16 static bool is_valid(T* value) {
return value !=
nullptr; }
21 : indexer_(other.indexer_)
22 , array_(other.array_) {}
24 : indexer_(std::move(other.indexer_))
25 , array_(std::move(other.array_)) {}
28 , array_(
indexer.size(), value) {}
38 const Indexer&
indexer()
const {
return indexer_; }
39 size_t capacity()
const {
return array_.size(); }
42 assert(i !=
size_t(-1));
46 auto&
array() {
return array_; }
47 const auto&
array()
const {
return array_; }
48 Value&
array(
size_t i) {
return array_[i]; }
49 const Value&
array(
size_t i)
const {
return array_[i]; }
51 auto begin()
const {
return std::views::filter(array_, IsValidPred<Value>::is_valid).begin(); }
52 auto end()
const {
return std::views::filter(array_, IsValidPred<Value>::is_valid).end(); }
56 swap(map1.indexer_, map2.indexer_);
57 swap(map1.array_, map2.array_);
61 const Indexer& indexer_;
68 auto i = map.
indexer().index(key);
69 return i != size_t(-1) ? map.
array()[i] :
nullptr;
72template<
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 std::span<T, N> with the following additional features:
This is a thin wrapper for absl::InlinedVector<T, N, / A> which in turn is a drop-in replacement for ...
Value * find(IndexMap< Indexer, Key, Value * > &map, Key key)