17 #ifndef MOMO_INCLUDE_GUARD_STDISH_VECTOR
18 #define MOMO_INCLUDE_GUARD_STDISH_VECTOR
22 #ifdef MOMO_HAS_CONTAINERS_RANGES
43 template<
typename TValue,
44 typename TAllocator = std::allocator<TValue>,
45 typename TArray = Array<TValue, MemManagerStd<TAllocator>>>
83 : mArray(MemManager(alloc))
88 : mArray(count, MemManager(alloc))
93 : mArray(count, value, MemManager(alloc))
97 template<
typename Iterator,
98 typename =
typename std::iterator_traits<Iterator>::iterator_category>
100 : mArray(first, last, MemManager(alloc))
105 : mArray(values, MemManager(alloc))
109 #ifdef MOMO_HAS_CONTAINERS_RANGES
110 template<std::ranges::input_range Range>
111 requires std::convertible_to<std::ranges::range_reference_t<Range>,
value_type>
113 : mArray(
std::ranges::
begin(values),
std::ranges::
end(values), MemManager(alloc))
116 #endif // MOMO_HAS_CONTAINERS_RANGES
119 : mArray(std::move(right.mArray))
124 noexcept(std::is_empty<allocator_type>::value)
125 : mArray(pvCreateArray(
std::move(right), alloc))
130 : mArray(right.mArray)
135 : mArray(right.mArray, MemManager(alloc))
142 noexcept(std::is_empty<allocator_type>::value ||
143 std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value)
147 bool propagate = std::is_empty<allocator_type>::value ||
148 std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value;
150 mArray = pvCreateArray(std::move(right), alloc);
159 bool propagate = std::is_empty<allocator_type>::value ||
160 std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value;
162 mArray = Array(right.mArray, MemManager(alloc));
175 MOMO_ASSERT(std::allocator_traits<allocator_type>::propagate_on_container_swap::value
177 mArray.Swap(right.mArray);
197 return mArray.GetBegin();
202 return mArray.GetBegin();
207 return mArray.GetEnd();
212 return mArray.GetEnd();
257 return mArray.GetItems();
262 return mArray.GetItems();
272 return std::allocator_traits<allocator_type>::max_size(
get_allocator());
277 return mArray.GetCount();
282 mArray.SetCount(
size);
287 mArray.SetCount(
size, value);
292 return mArray.IsEmpty();
302 return mArray.GetCapacity();
307 mArray.Reserve(count);
317 return mArray[index];
322 return mArray[index];
328 throw std::out_of_range(
"invalid vector subscript");
329 return mArray[index];
335 throw std::out_of_range(
"invalid vector subscript");
336 return mArray[index];
351 return mArray.GetBackItem();
356 return mArray.GetBackItem();
361 mArray.AddBack(std::move(value));
366 mArray.AddBack(value);
372 mArray.Insert(index, std::move(value));
379 mArray.Insert(index, value);
386 mArray.Insert(index, count, value);
390 template<
typename Iterator,
391 typename =
typename std::iterator_traits<Iterator>::iterator_category>
395 mArray.Insert(index, first, last);
402 mArray.Insert(index, values);
406 template<
typename... ValueArgs>
409 mArray.AddBackVar(std::forward<ValueArgs>(valueArgs)...);
413 template<
typename... ValueArgs>
417 mArray.InsertVar(index, std::forward<ValueArgs>(valueArgs)...);
421 #ifdef MOMO_HAS_CONTAINERS_RANGES
422 template<std::ranges::input_range Range>
423 requires std::convertible_to<std::ranges::range_reference_t<Range>,
value_type>
424 void append_range(Range&& values)
426 insert_range(
cend(), std::forward<Range>(values));
429 template<std::ranges::input_range Range>
430 requires std::convertible_to<std::ranges::range_reference_t<Range>,
value_type>
434 mArray.Insert(index, std::ranges::begin(values), std::ranges::end(values));
437 #endif // MOMO_HAS_CONTAINERS_RANGES
446 return erase(where, where + 1);
456 template<
typename ValueArg>
459 auto valueFilter = [&valueArg] (
const value_type& value)
460 {
return value == valueArg; };
461 return cont.mArray.Remove(valueFilter);
464 template<
typename ValueFilter>
467 return cont.mArray.Remove(valueFilter);
475 template<
typename Iterator,
476 typename =
typename std::iterator_traits<Iterator>::iterator_category>
477 void assign(Iterator first, Iterator last)
479 pvAssign(first, last);
482 void assign(std::initializer_list<value_type> values)
484 pvAssign(values.begin(), values.end());
487 #ifdef MOMO_HAS_CONTAINERS_RANGES
488 template<std::ranges::input_range Range>
489 requires std::convertible_to<std::ranges::range_reference_t<Range>,
value_type>
490 void assign_range(Range&& values)
492 pvAssign(std::ranges::begin(values), std::ranges::end(values));
494 #endif // MOMO_HAS_CONTAINERS_RANGES
498 return left.mArray.IsEqual(right.mArray);
501 #ifdef MOMO_HAS_THREE_WAY_COMPARISON
502 friend auto operator<=>(
const vector& left,
const vector& right)
503 requires requires (
const_reference ref) { std::tie(ref) <=> std::tie(ref); }
506 {
return std::tie(value1) <=> std::tie(value2); };
507 return std::lexicographical_compare_three_way(left.begin(), left.end(),
508 right.begin(), right.end(), comp);
513 return std::lexicographical_compare(left.
begin(), left.
end(), right.
begin(), right.
end());
522 if (right.get_allocator() == alloc)
523 return std::move(right.mArray);
524 Array array(std::make_move_iterator(right.begin()),
525 std::make_move_iterator(right.end()), MemManager(alloc));
530 template<
typename Iterator,
typename Sentinel>
531 void pvAssign(Iterator
begin, Sentinel
end)
540 #ifdef MOMO_HAS_DEDUCTION_GUIDES
544 template<
typename Allocator,
545 typename = decltype(std::declval<Allocator&>().allocate(
size_t{}))>
551 template<
typename Iterator,
552 typename Value =
typename std::iterator_traits<Iterator>::value_type,
553 typename Allocator = std::allocator<Value>,
554 typename = internal::vector_checker<Allocator>>
555 vector(Iterator, Iterator, Allocator = Allocator())
556 -> vector<Value, Allocator>;
558 #ifdef MOMO_HAS_CONTAINERS_RANGES
559 template<std::ranges::input_range Range,
560 typename Value = std::ranges::range_value_t<Range>,
561 typename Allocator = std::allocator<Value>,
562 typename = internal::vector_checker<Allocator>>
563 vector(std::from_range_t, Range&&, Allocator = Allocator())
564 -> vector<Value, Allocator>;
565 #endif // MOMO_HAS_CONTAINERS_RANGES
567 #endif // MOMO_HAS_DEDUCTION_GUIDES
578 template<
size_t tInternalCapacity,
typename TValue,
579 typename TAllocator = std::allocator<TValue>>
587 #endif // MOMO_INCLUDE_GUARD_STDISH_VECTOR