From 44c601d9ead6ba954ec95ef338ede704385e6ff4 Mon Sep 17 00:00:00 2001 From: morzhovets Date: Mon, 21 Oct 2024 21:55:53 +0400 Subject: [PATCH] std::forward_iterator --- include/momo/Array.h | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/include/momo/Array.h b/include/momo/Array.h index a76bfae1..c08df38d 100644 --- a/include/momo/Array.h +++ b/include/momo/Array.h @@ -494,18 +494,8 @@ class Array template explicit Array(ArgIterator begin, ArgIterator end, MemManager memManager = MemManager()) - : mData(std::forward_iterator ? SMath::Dist(begin, end) : 0, - std::move(memManager)) + : Array(begin, end, std::move(memManager), nullptr) { - typedef typename ItemTraits::template Creator> IterCreator; - MemManager& thisMemManager = GetMemManager(); - for (ArgIterator iter = begin; iter != end; ++iter) - { - if constexpr (std::forward_iterator) - pvAddBackNogrow(FastMovableFunctor(IterCreator(thisMemManager, *iter))); - else - pvAddBack(FastMovableFunctor(IterCreator(thisMemManager, *iter))); - } } Array(std::initializer_list items) @@ -921,6 +911,27 @@ class Array { } + template + explicit Array(ArgIterator begin, ArgIterator end, MemManager&& memManager, std::nullptr_t) + : mData(SMath::Dist(begin, end), std::move(memManager)) + { + typedef typename ItemTraits::template Creator> IterCreator; + MemManager& thisMemManager = GetMemManager(); + for (ArgIterator iter = begin; iter != end; ++iter) + pvAddBackNogrow(FastMovableFunctor(IterCreator(thisMemManager, *iter))); + } + + template + requires (!std::forward_iterator) + explicit Array(ArgIterator begin, ArgIterator end, MemManager&& memManager, std::nullptr_t) + : mData(std::move(memManager)) + { + typedef typename ItemTraits::template Creator> IterCreator; + MemManager& thisMemManager = GetMemManager(); + for (ArgIterator iter = begin; iter != end; ++iter) + pvAddBack(FastMovableFunctor(IterCreator(thisMemManager, *iter))); + } + size_t pvGrowCapacity(size_t minNewCapacity, ArrayGrowCause growCause, bool linear) const { size_t newCapacity = Settings::GrowCapacity(GetCapacity(),