Skip to content

Commit

Permalink
std::forward_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Oct 21, 2024
1 parent 44edade commit 44c601d
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions include/momo/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,8 @@ class Array

template<internal::conceptInputIterator ArgIterator>
explicit Array(ArgIterator begin, ArgIterator end, MemManager memManager = MemManager())
: mData(std::forward_iterator<ArgIterator> ? SMath::Dist(begin, end) : 0,
std::move(memManager))
: Array(begin, end, std::move(memManager), nullptr)
{
typedef typename ItemTraits::template Creator<std::iter_reference_t<ArgIterator>> IterCreator;
MemManager& thisMemManager = GetMemManager();
for (ArgIterator iter = begin; iter != end; ++iter)
{
if constexpr (std::forward_iterator<ArgIterator>)
pvAddBackNogrow(FastMovableFunctor(IterCreator(thisMemManager, *iter)));
else
pvAddBack(FastMovableFunctor(IterCreator(thisMemManager, *iter)));
}
}

Array(std::initializer_list<Item> items)
Expand Down Expand Up @@ -921,6 +911,27 @@ class Array
{
}

template<std::forward_iterator ArgIterator>
explicit Array(ArgIterator begin, ArgIterator end, MemManager&& memManager, std::nullptr_t)
: mData(SMath::Dist(begin, end), std::move(memManager))
{
typedef typename ItemTraits::template Creator<std::iter_reference_t<ArgIterator>> IterCreator;
MemManager& thisMemManager = GetMemManager();
for (ArgIterator iter = begin; iter != end; ++iter)
pvAddBackNogrow(FastMovableFunctor(IterCreator(thisMemManager, *iter)));
}

template<internal::conceptInputIterator ArgIterator>
requires (!std::forward_iterator<ArgIterator>)
explicit Array(ArgIterator begin, ArgIterator end, MemManager&& memManager, std::nullptr_t)
: mData(std::move(memManager))
{
typedef typename ItemTraits::template Creator<std::iter_reference_t<ArgIterator>> 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(),
Expand Down

0 comments on commit 44c601d

Please sign in to comment.