170 using store_type = StoreT<ValueT, std::allocator<ValueT>>;
171 static constexpr element_t block_type = TypeId;
183 template<
typename Iter>
188 typedef typename store_type::iterator iterator;
189 typedef typename store_type::reverse_iterator reverse_iterator;
190 typedef typename store_type::const_iterator const_iterator;
191 typedef typename store_type::const_reverse_iterator const_reverse_iterator;
192 typedef ValueT value_type;
195 template<
bool Mutable>
196 class base_range_type
198 using block_type = mdds::detail::mutable_t<base_element_block, Mutable>;
202 using iter_type = std::conditional_t<Mutable, iterator, const_iterator>;
204 base_range_type(block_type& blk) : m_blk(blk)
209 return element_block::begin(m_blk);
214 return element_block::end(m_blk);
219 using range_type = base_range_type<true>;
220 using const_range_type = base_range_type<false>;
222 bool operator==(
const Self& r)
const
224 return m_array == r.m_array;
227 bool operator!=(
const Self& r)
const
229 return !operator==(r);
232 static const value_type& at(
const base_element_block& block,
typename store_type::size_type pos)
234 return get(block).m_array.at(pos);
239 return get(block).m_array.at(pos);
244 return get(block).m_array.data();
249 return get(block).m_array.size();
254 return get(block).m_array.begin();
259 return get(block).m_array.end();
264 return get(block).m_array.begin();
269 return get(block).m_array.end();
274 return get(block).m_array.begin();
279 return get(block).m_array.end();
284 return get(block).m_array.rbegin();
289 return get(block).m_array.rend();
294 return get(block).m_array.rbegin();
299 return get(block).m_array.rend();
304 return get(block).m_array.rbegin();
309 return get(block).m_array.rend();
314 return const_range_type(block);
319 return range_type(block);
324#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
327 std::ostringstream os;
328 os <<
"incorrect block type: expected block type=" << TypeId
333 return static_cast<Self&
>(block);
338#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
341 std::ostringstream os;
342 os <<
"incorrect block type: expected block type=" << TypeId
347 return static_cast<const Self&
>(block);
352 get(blk).m_array[pos] = val;
357 val = get(blk).m_array[pos];
362 return get(blk).m_array[pos];
365 template<
typename T = ValueT>
368 get(blk).m_array.push_back(std::forward<T>(val));
371 template<
typename... Args>
374 get(blk).m_array.emplace_back(std::forward<Args>(args)...);
379 store_type& blk2 = get(blk).m_array;
380 blk2.insert(blk2.begin(), val);
383 static Self* create_block(
size_t init_size)
385 return new Self(init_size);
390 delete static_cast<const Self*
>(p);
395 store_type& st = get(blk).m_array;
400 if (new_size < (detail::get_block_capacity(st) / 2))
401 detail::shrink_to_fit(st);
407 const store_type& blk2 = get(blk).m_array;
408 for (
const auto& val : blk2)
409 std::cout << val <<
" ";
411 std::cout << std::endl;
420 store_type& blk2 = get(blk).m_array;
421 blk2.erase(blk2.begin() + pos);
426 store_type& blk2 = get(blk).m_array;
427 blk2.erase(blk2.begin() + pos, blk2.begin() + pos + size);
432 store_type& d = get(dest).m_array;
433 const store_type& s = get(src).m_array;
434 d.insert(d.end(), s.begin(), s.end());
437 static void append_values_from_block(
440 store_type& d = get(dest).m_array;
441 const store_type& s = get(src).m_array;
442 std::pair<const_iterator, const_iterator> its = get_iterator_pair(s, begin_pos, len);
443 detail::reserve(d, d.size() + len);
444 d.insert(d.end(), its.first, its.second);
447 static void assign_values_from_block(
450 store_type& d = get(dest).m_array;
451 const store_type& s = get(src).m_array;
452 std::pair<const_iterator, const_iterator> its = get_iterator_pair(s, begin_pos, len);
453 d.assign(its.first, its.second);
456 static void prepend_values_from_block(
459 store_type& d = get(dest).m_array;
460 const store_type& s = get(src).m_array;
461 std::pair<const_iterator, const_iterator> its = get_iterator_pair(s, begin_pos, len);
462 detail::reserve(d, d.size() + len);
463 d.insert(d.begin(), its.first, its.second);
468 store_type& st1 = get(blk1).m_array;
469 store_type& st2 = get(blk2).m_array;
470 assert(pos1 + len <= st1.size());
471 assert(pos2 + len <= st2.size());
473 typename store_type::iterator it1 = st1.begin(), it2 = st2.begin();
474 std::advance(it1, pos1);
475 std::advance(it2, pos2);
477 for (
size_t i = 0; i < len; ++i, ++it1, ++it2)
479 value_type v1 = *it1, v2 = *it2;
487 return get(left) == get(right);
490 template<
typename Iter>
491 static void set_values(
base_element_block& block,
size_t pos,
const Iter& it_begin,
const Iter& it_end)
493 store_type& d = get(block).m_array;
494 typename store_type::iterator it_dest = d.begin();
495 std::advance(it_dest, pos);
496 for (Iter it = it_begin; it != it_end; ++it, ++it_dest)
500 template<
typename Iter>
501 static void append_values(
base_element_block& block,
const Iter& it_begin,
const Iter& it_end)
503 store_type& d = get(block).m_array;
504 typename store_type::iterator it = d.end();
505 d.insert(it, it_begin, it_end);
508 template<
typename Iter>
509 static void prepend_values(
base_element_block& block,
const Iter& it_begin,
const Iter& it_end)
511 store_type& d = get(block).m_array;
512 d.insert(d.begin(), it_begin, it_end);
515 template<
typename Iter>
516 static void assign_values(
base_element_block& dest,
const Iter& it_begin,
const Iter& it_end)
518 store_type& d = get(dest).m_array;
519 d.assign(it_begin, it_end);
522 template<
typename Iter>
523 static void insert_values(
base_element_block& block,
size_t pos,
const Iter& it_begin,
const Iter& it_end)
525 store_type& blk = get(block).m_array;
526 blk.insert(blk.begin() + pos, it_begin, it_end);
531 const store_type& blk = get(block).m_array;
532 return detail::get_block_capacity(blk);
537 store_type& blk = get(block).m_array;
538 detail::reserve(blk, size);
543 store_type& blk = get(block).m_array;
544 detail::shrink_to_fit(blk);
548 static std::pair<const_iterator, const_iterator> get_iterator_pair(
549 const store_type& array,
size_t begin_pos,
size_t len)
551 assert(begin_pos + len <= array.size());
552 const_iterator it = array.begin();
553 std::advance(it, begin_pos);
554 const_iterator it_end = it;
555 std::advance(it_end, len);
556 return std::pair<const_iterator, const_iterator>(it, it_end);