From 42cdcfb6ec1f37d94f036ad5500b60b07b185f27 Mon Sep 17 00:00:00 2001 From: Krylov Yaroslav Date: Mon, 21 Aug 2023 23:43:30 +0400 Subject: [PATCH] update to get rid of usage if ureact's algorithm replacement is used --- include/ureact/detail/algorithm.hpp | 25 +++++++++++++++++++++---- tests/src/adaptor/observe.cpp | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/ureact/detail/algorithm.hpp b/include/ureact/detail/algorithm.hpp index b302f3f9..248e9024 100644 --- a/include/ureact/detail/algorithm.hpp +++ b/include/ureact/detail/algorithm.hpp @@ -10,18 +10,20 @@ #ifndef UREACT_DETAIL_ALGORITHM_HPP #define UREACT_DETAIL_ALGORITHM_HPP -#include - #include #ifdef UREACT_USE_STD_ALGORITHM # include +#else +# include +# include #endif UREACT_BEGIN_NAMESPACE // Partial alternative to is provided and used by default because library requires // only a few algorithms while standard is quite bloated +// also `next` and `distance` from are added, because standard is even more bloated namespace detail { @@ -72,6 +74,21 @@ void iter_swap( LhsForwardIt a, RhsForwardIt b ) swap( *a, *b ); } +// random_access_iterator_tag version of std::next() +template +auto next( LhsForwardIt iter, size_t n = 1 ) +{ + iter += n; + return iter; +} + +// random_access_iterator_tag version of std::distance() +template +auto distance( InputIter first, InputIter last ) +{ + return last - first; +} + // Code based on possible implementation at // https://en.cppreference.com/w/cpp/algorithm/partition template @@ -83,7 +100,7 @@ ForwardIt partition( ForwardIt first, ForwardIt last, Pred pred ) return first; } - for( ForwardIt i = std::next( first ); i != last; ++i ) + for( ForwardIt i = detail::next( first ); i != last; ++i ) { if( pred( *i ) ) { @@ -101,7 +118,7 @@ void sort( ForwardIt first, ForwardIt last ) { if( first == last ) return; - const auto pivot = *std::next( first, std::distance( first, last ) / 2 ); + const auto pivot = *detail::next( first, detail::distance( first, last ) / 2 ); const auto middle1 = detail::partition( first, last, [pivot]( const auto& em ) { return em < pivot; } ); const auto middle2 diff --git a/tests/src/adaptor/observe.cpp b/tests/src/adaptor/observe.cpp index 9af7f5f1..c757cc3b 100644 --- a/tests/src/adaptor/observe.cpp +++ b/tests/src/adaptor/observe.cpp @@ -7,6 +7,7 @@ // #include "ureact/adaptor/observe.hpp" +#include #include #include "catch2_extra.hpp"