30 using iterator =
typename Parent::iterator;
31 using const_iterator =
typename Parent::const_iterator;
35 ValueType& operator[](KeyType&& k)
37 return Parent::operator[](std::move(k));
40 ValueType& operator[](
const KeyType& k)
42 return Parent::operator[](k);
45 const ValueType& operator[](KeyType&& k)
const
47 return Parent::at(std::move(k));
50 const ValueType& operator[](
const KeyType& k)
const
57 struct contains_iterator
64 contains_iterator(
const iterator& p,
bool valid):
70 contains_iterator(
const contains_iterator& c):
71 mIterator(c.mIterator),
77 operator bool()
const noexcept {
81 iterator operator->()
const noexcept
85 iterator operator*()
const noexcept
90 struct const_contains_iterator
93 const_iterator mIterator;
97 const_contains_iterator(
const const_iterator& p,
bool valid):
103 const_contains_iterator(
const const_contains_iterator& c):
104 mIterator(c.mIterator),
110 operator bool()
const noexcept {
114 const_iterator operator->()
const noexcept
118 const_iterator operator*()
const noexcept
124 ValueType& at(
const KeyType& key) {
125 auto it = Parent::find(key);
126 if (it == Parent::end())
127 throw AException(
"no such element: " + AClass<KeyType>::toString(key));
130 const ValueType& at(
const KeyType& key)
const {
131 auto it = Parent::find(key);
132 if (it == Parent::end())
133 throw AException(
"no such element: " + AClass<KeyType>::toString(key));
140 auto it = Parent::find(key);
147 auto it = Parent::find(key);
152 AOptional<ValueType> optional(
const KeyType& key)
const noexcept {
153 auto it = Parent::find(key);
154 if (it == Parent::end()) {
160 AVector<KeyType> keyVector() {
162 r.reserve(Parent::size());
163 for (
auto& p : *
this) {
168 AVector<ValueType> valueVector() {
169 AVector<ValueType> r;
170 r.reserve(Parent::size());
171 for (
auto& p : *
this) {
184 template<
typename Factory>
186 static_assert(std::is_constructible_v<ValueType>,
"ValueType is expected to be default-constructible");
187 auto[it, isElementCreated] = Parent::insert(
typename Parent::value_type(keyType, ValueType{}));
188 static_assert(std::is_same_v<
decltype(it),
typename Parent::iterator>,
"govno");
189 if (isElementCreated) {
190 it->second = factory();
195 template<
typename BinaryOperation>
198 result.reserve(Parent::size());
199 std::transform(Parent::begin(), Parent::end(), std::back_inserter(result), [transformer = std::forward<BinaryOperation>(transformer)](
const typename Parent::value_type& p){
200 return transformer(p.first, p.second);
205 AVector<std::tuple<KeyType, ValueType>> toVector()
const {
206 return toVector([](
const KeyType& k,
const ValueType& v) {
207 return std::make_tuple(k, v);
239 UnaryOperation&& transformer) {
240 AMap<
decltype(transformer(*begin).first),
241 decltype(transformer(*begin).second)> result;
243 for (
auto it = begin; it != end; ++it) {
244 auto[key, value] = transformer(*it);
245 result[std::move(key)] = std::move(value);
253 UnaryOperation&& transformer) {
255 decltype(transformer(*begin).second)> result;
257 for (
auto it = begin; it != end; ++it) {
258 auto[key, value] = transformer(*it);
259 result[std::move(key)] = std::move(value);
auto to_map(Iterator begin, Iterator end, UnaryOperation &&transformer)
Transforms sequence to map.
Definition AMap.h:237