Skip to content

Commit

Permalink
BackInsertIteratorStd
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Dec 28, 2024
1 parent bd22ddc commit c4e6cc8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
42 changes: 21 additions & 21 deletions include/momo/ArrayUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,39 +297,39 @@ namespace internal
{
}

template<typename Iterator>
requires (!std::is_const_v<Iterator>)
Iterator& operator=(this Iterator& iter, Item&& item)
template<conceptMutableThisArg IteratorArg,
typename Iterator = std::decay_t<IteratorArg>>
Iterator& operator=(this IteratorArg&& iter, Item&& item)
{
iter.container->AddBack(std::move(item));
return iter;
static_cast<BackInsertIteratorStd&>(iter).container->AddBack(std::move(item));
return static_cast<Iterator&>(iter);
}

template<typename Iterator>
requires (!std::is_const_v<Iterator>)
Iterator& operator=(this Iterator& iter, const Item& item)
template<conceptMutableThisArg IteratorArg,
typename Iterator = std::decay_t<IteratorArg>>
Iterator& operator=(this IteratorArg&& iter, const Item& item)
{
iter.container->AddBack(item);
return iter;
static_cast<BackInsertIteratorStd&>(iter).container->AddBack(item);
return static_cast<Iterator&>(iter);
}

template<typename Iterator>
requires (!std::is_const_v<Iterator>)
Iterator& operator*(this Iterator& iter) noexcept
template<conceptMutableThisArg IteratorArg,
typename Iterator = std::decay_t<IteratorArg>>
Iterator& operator*(this IteratorArg&& iter) noexcept
{
return iter;
return static_cast<Iterator&>(iter);
}

template<typename Iterator>
requires (!std::is_const_v<Iterator>)
Iterator& operator++(this Iterator& iter) noexcept
template<conceptMutableThisArg IteratorArg,
typename Iterator = std::decay_t<IteratorArg>>
Iterator& operator++(this IteratorArg&& iter) noexcept
{
return iter;
return static_cast<Iterator&>(iter);
}

template<typename Iterator>
requires (!std::is_const_v<Iterator>)
Iterator operator++(this Iterator& iter, int) noexcept
template<conceptMutableThisArg IteratorArg,
typename Iterator = std::decay_t<IteratorArg>>
Iterator operator++(this IteratorArg&& iter, int) noexcept
{
return iter;
}
Expand Down
3 changes: 3 additions & 0 deletions include/momo/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ namespace internal
template<typename Predicate, typename... Args>
concept conceptPredicate = conceptConstFunctor<Predicate, bool, Args...>;

template<typename ThisArg>
concept conceptMutableThisArg = !std::is_const_v<std::remove_reference_t<ThisArg>>;

template<typename Object, typename QSrcObject>
using ConstLike = std::conditional_t<std::is_const_v<QSrcObject>, const Object, Object>;

Expand Down

0 comments on commit c4e6cc8

Please sign in to comment.