init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
allhaileris
2026-02-16 15:50:16 +03:00
commit afb81b8278
13816 changed files with 3689732 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_HPP
#define RANGES_V3_ACTION_HPP
#include <range/v3/action/action.hpp>
#include <range/v3/action/adjacent_remove_if.hpp>
#include <range/v3/action/concepts.hpp>
#include <range/v3/action/drop.hpp>
#include <range/v3/action/drop_while.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/action/insert.hpp>
#include <range/v3/action/join.hpp>
#include <range/v3/action/push_back.hpp>
#include <range/v3/action/push_front.hpp>
#include <range/v3/action/remove_if.hpp>
#include <range/v3/action/reverse.hpp>
#include <range/v3/action/shuffle.hpp>
#include <range/v3/action/slice.hpp>
#include <range/v3/action/sort.hpp>
#include <range/v3/action/split.hpp>
#include <range/v3/action/split_when.hpp>
#include <range/v3/action/stable_sort.hpp>
#include <range/v3/action/stride.hpp>
#include <range/v3/action/take.hpp>
#include <range/v3/action/take_while.hpp>
#include <range/v3/action/transform.hpp>
#include <range/v3/action/unique.hpp>
#include <range/v3/action/unstable_remove_if.hpp>
#endif

View File

@@ -0,0 +1,247 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_CONTAINER_ACTION_HPP
#define RANGES_V3_CONTAINER_ACTION_HPP
#include <type_traits>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/concepts.hpp>
#include <range/v3/functional/compose.hpp>
#include <range/v3/functional/concepts.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/functional/reference_wrapper.hpp>
#include <range/v3/functional/pipeable.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/utility/move.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
struct make_action_closure_fn
{
template<typename Fun>
constexpr actions::action_closure<Fun> operator()(Fun fun) const
{
return actions::action_closure<Fun>{static_cast<Fun &&>(fun)};
}
};
/// \sa make_action_closure_fn
RANGES_INLINE_VARIABLE(make_action_closure_fn, make_action_closure)
/// \cond
namespace detail
{
struct action_closure_base_
{};
}
/// \endcond
/// \concept invocable_action_closure_
/// \brief The \c invocable_action_closure_ concept
template(typename ActionFn, typename Rng)(
concept (invocable_action_closure_)(ActionFn, Rng),
!derived_from<invoke_result_t<ActionFn, Rng>, detail::action_closure_base_>
);
/// \concept invocable_action_closure
/// \brief The \c invocable_action_closure concept
template<typename ActionFn, typename Rng>
CPP_concept invocable_action_closure =
invocable<ActionFn, Rng> &&
CPP_concept_ref(ranges::invocable_action_closure_, ActionFn, Rng);
namespace actions
{
struct RANGES_STRUCT_WITH_ADL_BARRIER(action_closure_base)
: detail::action_closure_base_
{
// clang-format off
// Piping requires things are passed by value.
template(typename Rng, typename ActionFn)(
requires (!std::is_lvalue_reference<Rng>::value) AND
range<Rng> AND invocable_action_closure<ActionFn, Rng &>)
friend constexpr auto
operator|(Rng && rng, action_closure<ActionFn> act)
{
return aux::move(static_cast<ActionFn &&>(act)(rng));
}
#ifndef RANGES_WORKAROUND_CLANG_43400
template<typename Rng, typename ActionFn> // ******************************
friend constexpr auto // ******************************
operator|(Rng &, // ********* READ THIS **********
action_closure<ActionFn> const &) // ****** IF YOUR COMPILE *******
-> CPP_broken_friend_ret(Rng)( // ******** BREAKS HERE *********
requires range<Rng>) = delete; // ******************************
// **************************************************************************
// * When piping a range into an action, the range must be moved in. *
// **************************************************************************
#endif // RANGES_WORKAROUND_CLANG_43400
template<typename ActionFn, typename Pipeable>
friend constexpr auto operator|(action_closure<ActionFn> act, Pipeable pipe)
-> CPP_broken_friend_ret(action_closure<composed<Pipeable, ActionFn>>)(
requires (is_pipeable_v<Pipeable>))
{
return make_action_closure(compose(static_cast<Pipeable &&>(pipe),
static_cast<ActionFn &&>(act)));
}
template<typename Rng, typename ActionFn>
friend constexpr auto operator|=(Rng & rng, action_closure<ActionFn> act) //
-> CPP_broken_friend_ret(Rng &)(
requires range<Rng> && invocable<ActionFn, Rng &>)
{
static_cast<ActionFn &&>(act)(rng);
return rng;
}
// clang-format on
};
#ifdef RANGES_WORKAROUND_CLANG_43400
// clang-format off
namespace RANGES_ADL_BARRIER_FOR(action_closure_base)
{
template(typename Rng, typename ActionFn)( // *******************************
requires range<Rng>) // *******************************
constexpr Rng // ********** READ THIS **********
operator|(Rng &, // ******* IF YOUR COMPILE *******
action_closure<ActionFn> const &) // ********* BREAKS HERE *********
= delete; // *******************************
// ***************************************************************************
// * When piping a range into an action, the range must be moved in. *
// ***************************************************************************
} // namespace RANGES_ADL_BARRIER_FOR(action_closure_base)
// clang-format on
#endif // RANGES_WORKAROUND_CLANG_43400
template<typename ActionFn>
struct RANGES_EMPTY_BASES action_closure
: action_closure_base
, ActionFn
{
action_closure() = default;
constexpr explicit action_closure(ActionFn fn)
: ActionFn(static_cast<ActionFn &&>(fn))
{}
};
/// \cond
/// DEPRECATED STUFF
struct action_access_
{
template<typename Action>
struct impl
{
// clang-format off
template<typename... Ts, typename A = Action>
static constexpr auto CPP_auto_fun(bind)(Ts &&... ts)
(
return A::bind(static_cast<Ts &&>(ts)...)
)
// clang-format on
};
};
using action_access RANGES_DEPRECATED(
"action_access and actions::action<> are deprecated. Please "
"replace action<> with action_closure<> and discontinue use of "
"action_access.") = action_access_;
template<typename>
struct old_action_;
struct make_action_fn_
{
template<typename Fun>
constexpr old_action_<Fun> operator()(Fun fun) const
{
return old_action_<Fun>{static_cast<Fun &&>(fun)};
}
};
using make_action_fn RANGES_DEPRECATED(
"make_action_fn is deprecated. Please use "
"make_action_closure instead.") = make_action_fn_;
namespace
{
RANGES_DEPRECATED(
"make_action and actions::action<> has been deprecated. Please switch to "
"make_action_closure and action::action_closure.")
RANGES_INLINE_VAR constexpr auto & make_action =
static_const<make_action_fn_>::value;
} // namespace
template<typename Action>
struct old_action_ : pipeable_base
{
private:
Action act_;
friend pipeable_access;
public:
old_action_() = default;
constexpr explicit old_action_(Action a) noexcept(
std::is_nothrow_move_constructible<Action>::value)
: act_(detail::move(a))
{}
// Calling directly requires things are passed by reference.
template(typename Rng, typename... Rest)(
requires range<Rng> AND invocable<Action const &, Rng &, Rest...>)
invoke_result_t<Action const &, Rng &, Rest...> //
operator()(Rng & rng, Rest &&... rest) const
{
return invoke(act_, rng, static_cast<Rest &&>(rest)...);
}
// Currying overload.
// clang-format off
template(typename... Rest, typename A = Action)(
requires (sizeof...(Rest) != 0))
auto CPP_auto_fun(operator())(Rest &&... rest)(const)
(
return make_action_fn_{}(
action_access_::impl<A>::bind(act_,
static_cast<Rest &&>(rest)...))
)
// clang-format on
};
template<typename Action>
using action RANGES_DEPRECATED(
"The actions::action<> template is deprecated. Please switch to "
"action_closure") = old_action_<Action>;
/// \endcond
} // namespace actions
template<typename ActionFn>
RANGES_INLINE_VAR constexpr bool is_pipeable_v<actions::action_closure<ActionFn>> =
true;
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,68 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler
// Copyright Christopher Di Bella
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_ADJACENT_REMOVE_IF_HPP
#define RANGES_V3_ACTION_ADJACENT_REMOVE_IF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/algorithm/adjacent_remove_if.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct adjacent_remove_if_fn
{
template(typename Pred, typename Proj = identity)(
requires (!range<Pred>))
constexpr auto operator()(Pred pred, Proj proj = {}) const
{
return make_action_closure(
bind_back(adjacent_remove_if_fn{}, std::move(pred), std::move(proj)));
}
template(typename Rng, typename Pred, typename Proj = identity)(
requires forward_range<Rng> AND
erasable_range<Rng, iterator_t<Rng>, sentinel_t<Rng>> AND
indirect_relation<Pred, projected<iterator_t<Rng>, Proj>> AND
permutable<iterator_t<Rng>>)
Rng operator()(Rng && rng, Pred pred, Proj proj = {}) const
{
auto i = adjacent_remove_if(rng, std::move(pred), std::move(proj));
erase(rng, std::move(i), end(rng));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::adjacent_remove_if_fn
RANGES_INLINE_VARIABLE(adjacent_remove_if_fn, adjacent_remove_if)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGES_V3_ACTION_ADJACENT_REMOVE_IF_HPP

View File

@@ -0,0 +1,185 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_CONCEPTS_HPP
#define RANGES_V3_ACTION_CONCEPTS_HPP
#include <utility>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
template<typename T>
struct movable_input_iterator
{
using iterator_category = std::input_iterator_tag;
using value_type = T;
using difference_type = std::ptrdiff_t;
using pointer = T *;
using reference = T &&;
movable_input_iterator() = default;
movable_input_iterator & operator++();
movable_input_iterator operator++(int);
bool operator==(movable_input_iterator const &) const;
bool operator!=(movable_input_iterator const &) const;
T && operator*() const;
};
} // namespace detail
/// \endcond
/// \addtogroup group-range
/// @{
// clang-format off
/// \concept semi_container
/// \brief The \c semi_container concept
/// \c std::array is a \c semi_container, native arrays are not.
template<typename T>
CPP_concept semi_container =
forward_range<T> && default_constructible<uncvref_t<T>> &&
movable<uncvref_t<T>> &&
!view_<T>;
/// \concept container_
/// \brief The \c container_ concept
/// \c std::vector is a container, \c std::array is not
template(typename T)(
concept (container_)(T),
constructible_from<
uncvref_t<T>,
detail::movable_input_iterator<range_value_t<T>>,
detail::movable_input_iterator<range_value_t<T>>>
);
/// \concept container
/// \brief The \c container concept
template<typename T>
CPP_concept container =
semi_container<T> &&
CPP_concept_ref(ranges::container_, T);
/// \concept reservable_
/// \brief The \c reservable_ concept
template<typename C>
CPP_requires(reservable_,
requires(C & c, C const & cc) //
(
c.reserve(ranges::size(c)),
cc.capacity(),
cc.max_size(),
concepts::requires_<same_as<decltype(cc.capacity()),
decltype(ranges::size(c))>>,
concepts::requires_<same_as<decltype(cc.max_size()),
decltype(ranges::size(c))>>
));
/// \concept reservable
/// \brief The \c reservable concept
template<typename C>
CPP_concept reservable =
container<C> && sized_range<C> && CPP_requires_ref(ranges::reservable_, C);
/// \concept reservable_with_assign_
/// \brief The \c reservable_with_assign_ concept
template<typename C, typename I>
CPP_requires(reservable_with_assign_,
requires(C & c, I i) //
(
c.assign(i, i)
));
/// \concept reservable_with_assign
/// \brief The \c reservable_with_assign concept
template<typename C, typename I>
CPP_concept reservable_with_assign =
reservable<C> && //
input_iterator<I> && //
CPP_requires_ref(ranges::reservable_with_assign_, C, I);
/// \concept random_access_reservable
/// \brief The \c random_access_reservable concept
template<typename C>
CPP_concept random_access_reservable =
reservable<C> && random_access_range<C>;
// clang-format on
/// \cond
namespace detail
{
template(typename T)(
requires container<T>)
std::true_type is_lvalue_container_like(T &) noexcept
{
return {};
}
template(typename T)(
requires container<T>)
meta::not_<std::is_rvalue_reference<T>> //
is_lvalue_container_like(reference_wrapper<T>) noexcept
{
return {};
}
template(typename T)(
requires container<T>)
std::true_type is_lvalue_container_like(std::reference_wrapper<T>) noexcept
{
return {};
}
template(typename T)(
requires container<T>)
std::true_type is_lvalue_container_like(ref_view<T>) noexcept
{
return {};
}
template<typename T>
using is_lvalue_container_like_t =
decltype(detail::is_lvalue_container_like(std::declval<T>()));
} // namespace detail
/// \endcond
// clang-format off
/// \concept lvalue_container_like_
/// \brief The \c lvalue_container_like_ concept
template(typename T)(
concept (lvalue_container_like_)(T),
implicitly_convertible_to<detail::is_lvalue_container_like_t<T>, std::true_type>
);
/// \concept lvalue_container_like
/// \brief The \c lvalue_container_like concept
template<typename T>
CPP_concept lvalue_container_like =
forward_range<T> &&
CPP_concept_ref(ranges::lvalue_container_like_, T);
// clang-format on
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,65 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_DROP_HPP
#define RANGES_V3_ACTION_DROP_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct drop_fn
{
template(typename Int)(
requires detail::integer_like_<Int>)
constexpr auto operator()(Int n) const
{
RANGES_EXPECT(n >= Int(0));
return make_action_closure(bind_back(drop_fn{}, n));
}
template(typename Rng)(
requires forward_range<Rng> AND
erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>>)
Rng operator()(Rng && rng, range_difference_t<Rng> n) const
{
RANGES_EXPECT(n >= 0);
ranges::actions::erase(
rng, begin(rng), ranges::next(begin(rng), n, end(rng)));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::drop_fn
RANGES_INLINE_VARIABLE(drop_fn, drop)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,64 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_DROP_WHILE_HPP
#define RANGES_V3_ACTION_DROP_WHILE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/algorithm/find_if_not.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct drop_while_fn
{
template(typename Fun)(
requires (!range<Fun>))
constexpr auto operator()(Fun fun) const
{
return make_action_closure(bind_back(drop_while_fn{}, std::move(fun)));
}
template(typename Rng, typename Fun)(
requires forward_range<Rng> AND
indirect_unary_predicate<Fun, iterator_t<Rng>> AND
erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>>)
Rng operator()(Rng && rng, Fun fun) const
{
ranges::actions::erase(
rng, begin(rng), find_if_not(begin(rng), end(rng), std::move(fun)));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::drop_while_fn
RANGES_INLINE_VARIABLE(drop_while_fn, drop_while)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,84 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_ERASE_HPP
#define RANGES_V3_ACTION_ERASE_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/insert.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace adl_erase_detail
{
template(typename Cont, typename I, typename S)(
requires lvalue_container_like<Cont> AND forward_iterator<I> AND
sentinel_for<S, I>)
auto erase(Cont && cont, I first, S last) //
-> decltype(unwrap_reference(cont).erase(first, last))
{
return unwrap_reference(cont).erase(first, last);
}
struct erase_fn
{
template(typename Rng, typename I, typename S)(
requires range<Rng> AND forward_iterator<I> AND sentinel_for<S, I>)
auto operator()(Rng && rng, I first, S last) const
-> decltype(erase((Rng &&) rng, first, last))
{
return erase(static_cast<Rng &&>(rng), first, last);
}
};
} // namespace adl_erase_detail
/// \endcond
/// \ingroup group-actions
RANGES_INLINE_VARIABLE(adl_erase_detail::erase_fn, erase)
namespace actions
{
using ranges::erase;
}
/// \addtogroup group-range
/// @{
// clang-format off
/// \concept erasable_range_
/// \brief The \c erasable_range_ concept
template<typename Rng, typename I, typename S>
CPP_requires(erasable_range_,
requires(Rng && rng, I first, S last)
(
ranges::erase((Rng &&) rng, first, last)
)
);
/// \concept erasable_range
/// \brief The \c erasable_range concept
template<typename Rng, typename I, typename S>
CPP_concept erasable_range =
range<Rng> && CPP_requires_ref(ranges::erasable_range_, Rng, I, S);
// clang-format on
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,299 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_INSERT_HPP
#define RANGES_V3_ACTION_INSERT_HPP
#include <initializer_list>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/concepts.hpp>
#include <range/v3/algorithm/max.hpp>
#include <range/v3/iterator/common_iterator.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace adl_insert_detail
{
template<typename Cont, typename... Args>
using insert_result_t = decltype(
unwrap_reference(std::declval<Cont>()).insert(std::declval<Args>()...));
template(typename Cont, typename T)(
requires lvalue_container_like<Cont> AND
(!range<T> && constructible_from<range_value_t<Cont>, T>)) //
insert_result_t<Cont &, T> insert(Cont && cont, T && t)
{
return unwrap_reference(cont).insert(static_cast<T &&>(t));
}
template(typename Cont, typename I, typename S)(
requires lvalue_container_like<Cont> AND sentinel_for<S, I> AND (!range<S>))
insert_result_t<Cont &, detail::cpp17_iterator_t<I, S>,
detail::cpp17_iterator_t<I, S>>
insert(Cont && cont, I i, S j)
{
return unwrap_reference(cont).insert(detail::cpp17_iterator_t<I, S>{i},
detail::cpp17_iterator_t<I, S>{j});
}
template(typename Cont, typename Rng)(
requires lvalue_container_like<Cont> AND range<Rng>)
insert_result_t<Cont &, detail::range_cpp17_iterator_t<Rng>,
detail::range_cpp17_iterator_t<Rng>>
insert(Cont && cont, Rng && rng)
{
return unwrap_reference(cont).insert(
detail::range_cpp17_iterator_t<Rng>{ranges::begin(rng)},
detail::range_cpp17_iterator_t<Rng>{ranges::end(rng)});
}
template(typename Cont, typename I, typename T)(
requires lvalue_container_like<Cont> AND input_iterator<I> AND
(!range<T> && constructible_from<range_value_t<Cont>, T>)) //
insert_result_t<Cont &, I, T> insert(Cont && cont, I p, T && t)
{
return unwrap_reference(cont).insert(p, static_cast<T &&>(t));
}
template(typename Cont, typename I, typename N, typename T)(
requires lvalue_container_like<Cont> AND input_iterator<I> AND
integral<N> AND constructible_from<range_value_t<Cont>, T>)
insert_result_t<Cont &, I, N, T> insert(Cont && cont, I p, N n, T && t)
{
return unwrap_reference(cont).insert(p, n, static_cast<T &&>(t));
}
/// \cond
namespace detail
{
using ranges::detail::cpp17_iterator_t;
using ranges::detail::range_cpp17_iterator_t;
template(typename Cont, typename P)(
requires container<Cont> AND input_iterator<P> AND
random_access_reservable<Cont>)
iterator_t<Cont> insert_reserve_helper(
Cont & cont, P const p, range_size_t<Cont> const delta)
{
auto const old_size = ranges::size(cont);
auto const max_size = cont.max_size();
RANGES_EXPECT(delta <= max_size - old_size);
auto const new_size = old_size + delta;
auto const old_capacity = cont.capacity();
auto const index = p - ranges::begin(cont);
if(old_capacity < new_size)
{
auto const new_capacity =
(old_capacity <= max_size / 3 * 2)
? ranges::max(old_capacity + old_capacity / 2, new_size)
: max_size;
cont.reserve(new_capacity);
}
return ranges::begin(cont) + index;
}
template(typename Cont, typename P, typename I, typename S)(
requires sentinel_for<S, I> AND (!range<S>)) //
auto insert_impl(Cont && cont, P p, I i, S j, std::false_type)
-> decltype(unwrap_reference(cont).insert(
p, cpp17_iterator_t<I, S>{i}, cpp17_iterator_t<I, S>{j}))
{
using C = cpp17_iterator_t<I, S>;
return unwrap_reference(cont).insert(p, C{i}, C{j});
}
template(typename Cont, typename P, typename I, typename S)(
requires sized_sentinel_for<S, I> AND random_access_reservable<Cont> AND
(!range<S>)) //
auto insert_impl(Cont && cont_, P p, I i, S j, std::true_type)
-> decltype(unwrap_reference(cont_).insert(
ranges::begin(unwrap_reference(cont_)), cpp17_iterator_t<I, S>{i},
cpp17_iterator_t<I, S>{j}))
{
using C = cpp17_iterator_t<I, S>;
auto && cont = unwrap_reference(cont_);
auto const delta = static_cast<range_size_t<Cont>>(j - i);
auto pos = insert_reserve_helper(cont, std::move(p), delta);
return cont.insert(pos, C{std::move(i)}, C{std::move(j)});
}
template(typename Cont, typename I, typename Rng)(
requires range<Rng>)
auto insert_impl(Cont && cont, I p, Rng && rng, std::false_type)
-> decltype(unwrap_reference(cont).insert(
p, range_cpp17_iterator_t<Rng>{ranges::begin(rng)},
range_cpp17_iterator_t<Rng>{ranges::end(rng)}))
{
using C = range_cpp17_iterator_t<Rng>;
return unwrap_reference(cont).insert(
p, C{ranges::begin(rng)}, C{ranges::end(rng)});
}
template(typename Cont, typename I, typename Rng)(
requires random_access_reservable<Cont> AND sized_range<Rng>)
auto insert_impl(Cont && cont_, I p, Rng && rng, std::true_type)
-> decltype(unwrap_reference(cont_).insert(
begin(unwrap_reference(cont_)),
range_cpp17_iterator_t<Rng>{ranges::begin(rng)},
range_cpp17_iterator_t<Rng>{ranges::end(rng)}))
{
using C = range_cpp17_iterator_t<Rng>;
auto && cont = unwrap_reference(cont_);
auto const delta = static_cast<range_size_t<Cont>>(ranges::size(rng));
auto pos = insert_reserve_helper(cont, std::move(p), delta);
return cont.insert(pos, C{ranges::begin(rng)}, C{ranges::end(rng)});
}
} // namespace detail
/// \endcond
template(typename Cont, typename P, typename I, typename S)(
requires lvalue_container_like<Cont> AND input_iterator<P> AND
sentinel_for<S, I> AND
(!range<S>)) //
auto insert(Cont && cont, P p, I i, S j) //
-> decltype(detail::insert_impl(
static_cast<Cont &&>(cont),
static_cast<P &&>(p),
static_cast<I &&>(i),
static_cast<S &&>(j),
meta::bool_<random_access_reservable<Cont> && //
sized_sentinel_for<S, I>>{}))
{
return detail::insert_impl(static_cast<Cont &&>(cont),
static_cast<P &&>(p),
static_cast<I &&>(i),
static_cast<S &&>(j),
meta::bool_<random_access_reservable<Cont> &&
sized_sentinel_for<S, I>>{});
}
template(typename Cont, typename I, typename Rng)(
requires lvalue_container_like<Cont> AND input_iterator<I> AND range<Rng>)
auto insert(Cont && cont, I p, Rng && rng)
-> decltype(detail::insert_impl(
static_cast<Cont &&>(cont), std::move(p), static_cast<Rng &&>(rng),
meta::bool_<random_access_reservable<Cont> && sized_range<Rng>>{}))
{
return detail::insert_impl(static_cast<Cont &&>(cont),
std::move(p),
static_cast<Rng &&>(rng),
meta::bool_<random_access_reservable<Cont> &&
sized_range<Rng>>{});
}
struct insert_fn
{
template<typename Rng, typename... Args>
using insert_result_t =
decltype(insert(std::declval<Rng>(), std::declval<Args>()...));
template(typename Rng, typename T)(
requires range<Rng> AND
(!range<T>) AND constructible_from<range_value_t<Rng>, T>)
insert_result_t<Rng, T> operator()(Rng && rng, T && t) const
{
return insert(static_cast<Rng &&>(rng), static_cast<T &&>(t));
}
template(typename Rng, typename Rng2)(
requires range<Rng> AND range<Rng2>)
insert_result_t<Rng, Rng2> operator()(Rng && rng, Rng2 && rng2) const
{
static_assert(!is_infinite<Rng>::value,
"Attempting to insert an infinite range into a container");
return insert(static_cast<Rng &&>(rng), static_cast<Rng2 &&>(rng2));
}
template(typename Rng, typename T)(
requires range<Rng>)
insert_result_t<Rng, std::initializer_list<T> &> //
operator()(Rng && rng, std::initializer_list<T> rng2) const
{
return insert(static_cast<Rng &&>(rng), rng2);
}
template(typename Rng, typename I, typename S)(
requires range<Rng> AND sentinel_for<S, I> AND (!range<S>)) //
insert_result_t<Rng, I, S> operator()(Rng && rng, I i, S j) const
{
return insert(static_cast<Rng &&>(rng), std::move(i), std::move(j));
}
template(typename Rng, typename I, typename T)(
requires range<Rng> AND input_iterator<I> AND
(!range<T>) AND constructible_from<range_value_t<Rng>, T>)
insert_result_t<Rng, I, T> operator()(Rng && rng, I p, T && t) const
{
return insert(
static_cast<Rng &&>(rng), std::move(p), static_cast<T &&>(t));
}
template(typename Rng, typename I, typename Rng2)(
requires range<Rng> AND input_iterator<I> AND range<Rng2>)
insert_result_t<Rng, I, Rng2> operator()(Rng && rng, I p, Rng2 && rng2) const
{
static_assert(!is_infinite<Rng>::value,
"Attempting to insert an infinite range into a container");
return insert(
static_cast<Rng &&>(rng), std::move(p), static_cast<Rng2 &&>(rng2));
}
template(typename Rng, typename I, typename T)(
requires range<Rng> AND input_iterator<I>)
insert_result_t<Rng, I, std::initializer_list<T> &> //
operator()(Rng && rng, I p, std::initializer_list<T> rng2) const
{
return insert(static_cast<Rng &&>(rng), std::move(p), rng2);
}
template(typename Rng, typename I, typename N, typename T)(
requires range<Rng> AND input_iterator<I> AND integral<N> AND
(!range<T>) AND constructible_from<range_value_t<Rng>, T>)
insert_result_t<Rng, I, N, T> operator()(Rng && rng, I p, N n, T && t) const
{
return insert(
static_cast<Rng &&>(rng), std::move(p), n, static_cast<T &&>(t));
}
template(typename Rng, typename P, typename I, typename S)(
requires range<Rng> AND input_iterator<P> AND sentinel_for<S, I> AND
(!range<S>)) //
insert_result_t<Rng, P, I, S> operator()(Rng && rng, P p, I i, S j) const
{
return insert(
static_cast<Rng &&>(rng), std::move(p), std::move(i), std::move(j));
}
};
} // namespace adl_insert_detail
/// \endcond
/// \ingroup group-actions
RANGES_INLINE_VARIABLE(adl_insert_detail::insert_fn, insert)
namespace actions
{
using ranges::insert;
}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,68 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_JOIN_HPP
#define RANGES_V3_ACTION_JOIN_HPP
#include <vector>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/concepts.hpp>
#include <range/v3/action/push_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
template<typename Rng>
using join_action_value_t_ =
meta::if_c<(bool)ranges::container<range_value_t<Rng>>, //
range_value_t<Rng>, //
std::vector<range_value_t<range_value_t<Rng>>>>;
struct join_fn
{
template(typename Rng)(
requires input_range<Rng> AND input_range<range_value_t<Rng>> AND
semiregular<join_action_value_t_<Rng>>)
join_action_value_t_<Rng> operator()(Rng && rng) const
{
join_action_value_t_<Rng> ret;
auto last = ranges::end(rng);
for(auto it = begin(rng); it != last; ++it)
push_back(ret, *it);
return ret;
}
};
/// \relates actions::join_fn
/// \sa action_closure
RANGES_INLINE_VARIABLE(action_closure<join_fn>, join)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,149 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_PUSH_BACK_HPP
#define RANGES_V3_ACTION_PUSH_BACK_HPP
#include <utility>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/insert.hpp>
#include <range/v3/detail/with_braced_init_args.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
/// \cond
namespace adl_push_back_detail
{
/// \endcond
template<typename Cont, typename T>
using push_back_t = decltype(static_cast<void>(
unwrap_reference(std::declval<Cont &>()).push_back(std::declval<T>())));
template<typename Cont, typename Rng>
using insert_t = decltype(static_cast<void>(
ranges::insert(std::declval<Cont &>(), std::declval<sentinel_t<Cont>>(),
std::declval<Rng>())));
template(typename Cont, typename T)(
requires lvalue_container_like<Cont> AND
(!range<T>) AND constructible_from<range_value_t<Cont>, T>)
push_back_t<Cont, T> push_back(Cont && cont, T && t)
{
unwrap_reference(cont).push_back(static_cast<T &&>(t));
}
template(typename Cont, typename Rng)(
requires lvalue_container_like<Cont> AND range<Rng>)
insert_t<Cont, Rng> push_back(Cont && cont, Rng && rng)
{
ranges::insert(cont, end(cont), static_cast<Rng &&>(rng));
}
/// \cond
// clang-format off
/// \concept can_push_back_frag_
/// \brief The \c can_push_back_frag_ concept
template<typename Rng, typename T>
CPP_requires(can_push_back_frag_,
requires(Rng && rng, T && t) //
(
push_back(rng, (T &&) t)
));
/// \concept can_push_back_
/// \brief The \c can_push_back_ concept
template<typename Rng, typename T>
CPP_concept can_push_back_ =
CPP_requires_ref(adl_push_back_detail::can_push_back_frag_, Rng, T);
// clang-format on
/// \endcond
struct push_back_fn
{
template<typename T>
constexpr auto operator()(T && val) const
{
return make_action_closure(
bind_back(push_back_fn{}, static_cast<T &&>(val)));
}
template(typename T)(
requires range<T &>)
constexpr auto operator()(T & t) const
{
return make_action_closure(
bind_back(push_back_fn{}, detail::reference_wrapper_<T>(t)));
}
template<typename T>
constexpr auto operator()(std::initializer_list<T> val) const
{
return make_action_closure(bind_back(push_back_fn{}, val));
}
template(typename Rng, typename T)(
requires input_range<Rng> AND can_push_back_<Rng, T> AND
(range<T> || constructible_from<range_value_t<Rng>, T>)) //
Rng operator()(Rng && rng, T && t) const //
{
push_back(rng, static_cast<T &&>(t));
return static_cast<Rng &&>(rng);
}
template(typename Rng, typename T)(
requires input_range<Rng> AND
can_push_back_<Rng, std::initializer_list<T>> AND
constructible_from<range_value_t<Rng>, T const &>)
Rng operator()(Rng && rng, std::initializer_list<T> t) const //
{
push_back(rng, t);
return static_cast<Rng &&>(rng);
}
/// \cond
template<typename Rng, typename T>
invoke_result_t<push_back_fn, Rng, T &> //
operator()(Rng && rng, detail::reference_wrapper_<T> r) const
{
return (*this)(static_cast<Rng &&>(rng), r.get());
}
/// \endcond
};
/// \cond
} // namespace adl_push_back_detail
/// \endcond
namespace actions
{
RANGES_INLINE_VARIABLE(adl_push_back_detail::push_back_fn, push_back)
} // namespace actions
using actions::push_back;
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,149 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_PUSH_FRONT_HPP
#define RANGES_V3_ACTION_PUSH_FRONT_HPP
#include <utility>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/insert.hpp>
#include <range/v3/detail/with_braced_init_args.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
/// \cond
namespace adl_push_front_detail
{
/// \endcond
template<typename Cont, typename T>
using push_front_t = decltype(static_cast<void>(
unwrap_reference(std::declval<Cont &>()).push_front(std::declval<T>())));
template<typename Cont, typename Rng>
using insert_t = decltype(static_cast<void>(
ranges::insert(std::declval<Cont &>(), std::declval<iterator_t<Cont>>(),
std::declval<Rng>())));
template(typename Cont, typename T)(
requires lvalue_container_like<Cont> AND
(!range<T>) AND constructible_from<range_value_t<Cont>, T>)
push_front_t<Cont, T> push_front(Cont && cont, T && t)
{
unwrap_reference(cont).push_front(static_cast<T &&>(t));
}
template(typename Cont, typename Rng)(
requires lvalue_container_like<Cont> AND range<Rng>)
insert_t<Cont, Rng> push_front(Cont && cont, Rng && rng)
{
ranges::insert(cont, begin(cont), static_cast<Rng &&>(rng));
}
/// \cond
// clang-format off
/// \concept can_push_front_frag_
/// \brief The \c can_push_front_frag_ concept
template<typename Rng, typename T>
CPP_requires(can_push_front_frag_,
requires(Rng && rng, T && t) //
(
push_front(rng, (T &&) t)
));
/// \concept can_push_front_
/// \brief The \c can_push_front_ concept
template<typename Rng, typename T>
CPP_concept can_push_front_ =
CPP_requires_ref(adl_push_front_detail::can_push_front_frag_, Rng, T);
// clang-format on
/// \endcond
struct push_front_fn
{
template<typename T>
constexpr auto operator()(T && val) const
{
return make_action_closure(
bind_back(push_front_fn{}, static_cast<T &&>(val)));
}
template<typename T>
constexpr auto operator()(std::initializer_list<T> val) const
{
return make_action_closure(bind_back(push_front_fn{}, val));
}
template(typename T)(
requires range<T &>)
constexpr auto operator()(T & t) const
{
return make_action_closure(
bind_back(push_front_fn{}, detail::reference_wrapper_<T>(t)));
}
template(typename Rng, typename T)(
requires input_range<Rng> AND can_push_front_<Rng, T> AND
(range<T> || constructible_from<range_value_t<Rng>, T>)) //
Rng operator()(Rng && rng, T && t) const //
{
push_front(rng, static_cast<T &&>(t));
return static_cast<Rng &&>(rng);
}
template(typename Rng, typename T)(
requires input_range<Rng> AND
can_push_front_<Rng, std::initializer_list<T>> AND
constructible_from<range_value_t<Rng>, T const &>)
Rng operator()(Rng && rng, std::initializer_list<T> t) const //
{
push_front(rng, t);
return static_cast<Rng &&>(rng);
}
/// \cond
template<typename Rng, typename T>
invoke_result_t<push_front_fn, Rng, T &> //
operator()(Rng && rng, detail::reference_wrapper_<T> r) const
{
return (*this)(static_cast<Rng &&>(rng), r.get());
}
/// \endcond
};
/// \cond
} // namespace adl_push_front_detail
/// \endcond
namespace actions
{
RANGES_INLINE_VARIABLE(adl_push_front_detail::push_front_fn, push_front)
} // namespace actions
using actions::push_front;
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,74 @@
/// \file
// Range v3 library
//
// Copyright Andrey Diduh 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_REMOVE_HPP
#define RANGES_V3_ACTION_REMOVE_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/algorithm/remove.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct remove_fn
{
template(typename V, typename P)(
requires (!range<V>))
constexpr auto operator()(V && value, P proj) const
{
return make_action_closure(
bind_back(remove_fn{}, static_cast<V &&>(value), std::move(proj)));
}
template<typename V>
constexpr auto operator()(V && value) const
{
return make_action_closure(
bind_back(remove_fn{}, static_cast<V &&>(value), identity{}));
}
template(typename Rng, typename V, typename P = identity)(
requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
erasable_range<Rng, iterator_t<Rng>, sentinel_t<Rng>> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>,
V const *>)
Rng operator()(Rng && rng, V const & value, P proj = {}) const
{
auto it = ranges::remove(rng, value, std::move(proj));
ranges::erase(rng, it, ranges::end(rng));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::remove_fn
RANGES_INLINE_VARIABLE(remove_fn, remove)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,70 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_REMOVE_IF_HPP
#define RANGES_V3_ACTION_REMOVE_IF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/algorithm/remove_if.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
// TODO Look at all the special cases handled by erase_if in Library Fundamentals 2
/// \addtogroup group-actions
/// @{
namespace actions
{
struct remove_if_fn
{
template(typename C, typename P = identity)(
requires (!range<C>))
constexpr auto operator()(C pred, P proj = P{}) const
{
return make_action_closure(
bind_back(remove_if_fn{}, std::move(pred), std::move(proj)));
}
template(typename Rng, typename C, typename P = identity)(
requires forward_range<Rng> AND
erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>> AND
permutable<iterator_t<Rng>> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
Rng operator()(Rng && rng, C pred, P proj = P{}) const
{
auto it = ranges::remove_if(rng, std::move(pred), std::move(proj));
ranges::erase(rng, it, ranges::end(rng));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::remove_if_fn
RANGES_INLINE_VARIABLE(remove_if_fn, remove_if)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,55 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
// Copyright Gonzalo Brito Gadeschi 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_REVERSE_HPP
#define RANGES_V3_ACTION_REVERSE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/algorithm/reverse.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
/// Reversed the source range in-place.
struct reverse_fn
{
template(typename Rng)(
requires bidirectional_range<Rng> AND permutable<iterator_t<Rng>>)
Rng operator()(Rng && rng) const
{
ranges::reverse(rng);
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::reverse_fn
/// \sa action_closure
RANGES_INLINE_VARIABLE(action_closure<reverse_fn>, reverse)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,83 @@
/// \file
// Range v3 library
//
// Copyright Filip Matzner 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_SHUFFLE_HPP
#define RANGES_V3_ACTION_SHUFFLE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/algorithm/shuffle.hpp>
#include <range/v3/functional/bind.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct shuffle_fn
{
template(typename Gen)(
requires uniform_random_bit_generator<Gen>)
constexpr auto operator()(Gen & gen) const
{
return make_action_closure(
bind_back(shuffle_fn{}, detail::reference_wrapper_<Gen>(gen)));
}
template(typename Gen)(
requires uniform_random_bit_generator<Gen>)
constexpr auto operator()(Gen && gen) const
{
return make_action_closure(
bind_back(shuffle_fn{}, static_cast<Gen &&>(gen)));
}
template(typename Rng, typename Gen)(
requires random_access_range<Rng> AND permutable<iterator_t<Rng>> AND
uniform_random_bit_generator<std::remove_reference_t<Gen>> AND
convertible_to<invoke_result_t<Gen &>, range_difference_t<Rng>>)
Rng operator()(Rng && rng, Gen && gen) const
{
ranges::shuffle(rng, static_cast<Gen &&>(gen));
return static_cast<Rng &&>(rng);
}
/// \cond
template<typename Rng, typename T>
invoke_result_t<shuffle_fn, Rng, T &> //
operator()(Rng && rng, detail::reference_wrapper_<T> r) const
{
return (*this)(static_cast<Rng &&>(rng), r.get());
}
/// \endcond
};
/// \relates actions::shuffle_fn
/// \sa `action_closure`
RANGES_INLINE_VARIABLE(shuffle_fn, shuffle)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,154 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_SLICE_HPP
#define RANGES_V3_ACTION_SLICE_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/interface.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct slice_fn
{
private:
template<typename D>
using diff_t = range_difference_t<D>;
public:
// Overloads for the pipe syntax: rng | actions::slice(from, to)
template(typename D)(
requires integral<D>)
constexpr auto operator()(D from, D to) const
{
return make_action_closure(bind_back(slice_fn{}, from, to));
}
template(typename D)(
requires integral<D>)
constexpr auto operator()(D from, detail::from_end_<D> to) const
{
return make_action_closure(bind_back(slice_fn{}, from, to));
}
template(typename D)(
requires integral<D>)
constexpr auto operator()(detail::from_end_<D> from, detail::from_end_<D> to)
const
{
return make_action_closure(bind_back(slice_fn{}, from, to));
}
template(typename D)(
requires integral<D>)
constexpr auto operator()(D from, end_fn const & to) const
{
return make_action_closure(bind_back(slice_fn{}, from, to));
}
template(typename D)(
requires integral<D>)
constexpr auto operator()(detail::from_end_<D> from, end_fn const & to) const
{
return make_action_closure(bind_back(slice_fn{}, from, to));
}
template(typename Rng, typename I = iterator_t<Rng>)(
requires forward_range<Rng> AND erasable_range<Rng &, I, I>)
Rng operator()(Rng && rng, diff_t<Rng> from, diff_t<Rng> to) const
{
RANGES_EXPECT(0 <= from && 0 <= to && from <= to);
RANGES_EXPECT(!sized_range<Rng> || to <= distance(rng));
ranges::actions::erase(rng, begin(rng), next(begin(rng), from));
ranges::actions::erase(rng, next(begin(rng), to - from), end(rng));
return static_cast<Rng &&>(rng);
}
template(typename Rng, typename I = iterator_t<Rng>)(
requires bidirectional_range<Rng> AND erasable_range<Rng &, I, I>)
Rng operator()(Rng && rng,
diff_t<Rng> from,
detail::from_end_<diff_t<Rng>> to) const
{
RANGES_EXPECT(0 <= from && to.dist_ <= 0);
RANGES_EXPECT(!sized_range<Rng> || from - to.dist_ <= distance(rng));
ranges::actions::erase(rng, begin(rng), next(begin(rng), from));
if(to.dist_ != 0)
{
auto const last = next(begin(rng), end(rng));
ranges::actions::erase(rng, prev(last, -to.dist_), last);
}
return static_cast<Rng &&>(rng);
}
template(typename Rng, typename I = iterator_t<Rng>)(
requires bidirectional_range<Rng> AND erasable_range<Rng &, I, I>)
Rng operator()(Rng && rng,
detail::from_end_<diff_t<Rng>> from,
detail::from_end_<diff_t<Rng>> to) const
{
RANGES_EXPECT(from.dist_ <= 0 && to.dist_ <= 0 && from.dist_ <= to.dist_);
RANGES_EXPECT(!sized_range<Rng> || 0 <= distance(rng) + from.dist_);
auto last = next(begin(rng), end(rng));
ranges::actions::erase(rng, prev(last, -to.dist_), last);
last = next(begin(rng), end(rng));
ranges::actions::erase(
rng, begin(rng), prev(last, to.dist_ - from.dist_));
return static_cast<Rng &&>(rng);
}
template(typename Rng, typename I = iterator_t<Rng>)(
requires forward_range<Rng> AND erasable_range<Rng &, I, I>)
Rng operator()(Rng && rng, diff_t<Rng> from, end_fn const &) const
{
RANGES_EXPECT(0 <= from);
RANGES_EXPECT(!sized_range<Rng> || from <= distance(rng));
ranges::actions::erase(rng, begin(rng), next(begin(rng), from));
return static_cast<Rng &&>(rng);
}
template(typename Rng, typename I = iterator_t<Rng>)(
requires bidirectional_range<Rng> AND erasable_range<Rng &, I, I>)
Rng operator()(Rng && rng,
detail::from_end_<diff_t<Rng>> from,
end_fn const &) const
{
RANGES_EXPECT(from.dist_ <= 0);
RANGES_EXPECT(!sized_range<Rng> || 0 <= distance(rng) + from.dist_);
auto const last = next(begin(rng), end(rng));
ranges::actions::erase(rng, begin(rng), prev(last, -from.dist_));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::slice_fn
RANGES_INLINE_VARIABLE(slice_fn, slice)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,64 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_SORT_HPP
#define RANGES_V3_ACTION_SORT_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/algorithm/sort.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct sort_fn
{
template(typename C, typename P = identity)(
requires (!range<C>))
constexpr auto operator()(C pred, P proj = {}) const
{
return make_action_closure(
bind_back(sort_fn{}, std::move(pred), std::move(proj)));
}
template(typename Rng, typename C = less, typename P = identity)(
requires forward_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
Rng operator()(Rng && rng, C pred = {}, P proj = {}) const
{
ranges::sort(rng, std::move(pred), std::move(proj));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::sort_fn
/// \sa action_closure
RANGES_INLINE_VARIABLE(action_closure<sort_fn>, sort)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,106 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_SPLIT_HPP
#define RANGES_V3_ACTION_SPLIT_HPP
#include <vector>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/concepts.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/split.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct split_fn
{
template<typename Rng>
using split_value_t =
meta::if_c<(bool)ranges::container<Rng>, //
uncvref_t<Rng>, std::vector<range_value_t<Rng>>>;
template(typename T)(
requires range<T &>)
constexpr auto operator()(T & t) const
{
return make_action_closure(
bind_back(split_fn{}, detail::reference_wrapper_<T>(t)));
}
template<typename T>
constexpr auto operator()(T && t) const
{
return make_action_closure(bind_back(split_fn{}, static_cast<T &&>(t)));
}
// BUGBUG something is not right with the actions. It should be possible
// to move a container into a split and have elements moved into the result.
template(typename Rng)(
requires input_range<Rng> AND indirectly_comparable<
iterator_t<Rng>, range_value_t<Rng> const *, ranges::equal_to>)
std::vector<split_value_t<Rng>> //
operator()(Rng && rng, range_value_t<Rng> val) const
{
return views::split(rng, std::move(val)) |
to<std::vector<split_value_t<Rng>>>();
}
template(typename Rng, typename Pattern)(
requires input_range<Rng> AND viewable_range<Pattern> AND
forward_range<Pattern> AND
indirectly_comparable<
iterator_t<Rng>,
iterator_t<Pattern>,
ranges::equal_to> AND
(forward_range<Rng> || detail::tiny_range<Pattern>)) //
std::vector<split_value_t<Rng>> operator()(Rng && rng, Pattern && pattern)
const
{
return views::split(rng, static_cast<Pattern &&>(pattern)) |
to<std::vector<split_value_t<Rng>>>();
}
/// \cond
template<typename Rng, typename T>
invoke_result_t<split_fn, Rng, T &> //
operator()(Rng && rng, detail::reference_wrapper_<T> r) const
{
return (*this)(static_cast<Rng &&>(rng), r.get());
}
/// \endcond
};
/// \relates actions::split_fn
RANGES_INLINE_VARIABLE(split_fn, split)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,90 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_SPLIT_WHEN_HPP
#define RANGES_V3_ACTION_SPLIT_WHEN_HPP
#include <vector>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/concepts.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/split_when.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct split_when_fn
{
template<typename Rng>
using split_value_t =
meta::if_c<(bool)ranges::container<Rng>, //
uncvref_t<Rng>, std::vector<range_value_t<Rng>>>;
template<typename Fun>
constexpr auto operator()(Fun fun) const
{
return make_action_closure(
bind_back(split_when_fn{}, static_cast<Fun &&>(fun)));
}
// BUGBUG something is not right with the actions. It should be possible
// to move a container into a split and have elements moved into the result.
template(typename Rng, typename Fun)(
requires forward_range<Rng> AND
invocable<Fun &, iterator_t<Rng>, sentinel_t<Rng>> AND
invocable<Fun &, iterator_t<Rng>, iterator_t<Rng>> AND
copy_constructible<Fun> AND
convertible_to<invoke_result_t<Fun &, iterator_t<Rng>,
sentinel_t<Rng>>,
std::pair<bool, iterator_t<Rng>>>)
std::vector<split_value_t<Rng>> operator()(Rng && rng, Fun fun) const
{
return views::split_when(rng, std::move(fun)) |
to<std::vector<split_value_t<Rng>>>();
}
template(typename Rng, typename Fun)(
requires forward_range<Rng> AND
predicate<Fun const &, range_reference_t<Rng>> AND
copy_constructible<Fun>)
std::vector<split_value_t<Rng>> operator()(Rng && rng, Fun fun) const
{
return views::split_when(rng, std::move(fun)) |
to<std::vector<split_value_t<Rng>>>();
}
};
/// \relates actions::split_when_fn
RANGES_INLINE_VARIABLE(split_when_fn, split_when)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,64 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_STABLE_SORT_HPP
#define RANGES_V3_ACTION_STABLE_SORT_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/algorithm/stable_sort.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct stable_sort_fn
{
template(typename C, typename P = identity)(
requires (!range<C>))
constexpr auto operator()(C pred, P proj = P{}) const
{
return make_action_closure(
bind_back(stable_sort_fn{}, std::move(pred), std::move(proj)));
}
template(typename Rng, typename C = less, typename P = identity)(
requires forward_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
Rng operator()(Rng && rng, C pred = C{}, P proj = P{}) const
{
ranges::stable_sort(rng, std::move(pred), std::move(proj));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::stable_sort_fn
/// \sa action_closure
RANGES_INLINE_VARIABLE(action_closure<stable_sort_fn>, stable_sort)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,79 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_STRIDE_HPP
#define RANGES_V3_ACTION_STRIDE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct stride_fn
{
template(typename D)(
requires detail::integer_like_<D>)
constexpr auto operator()(D step) const
{
return make_action_closure(bind_back(stride_fn{}, step));
}
template(typename Rng, typename D = range_difference_t<Rng>)(
requires forward_range<Rng> AND
erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>> AND
permutable<iterator_t<Rng>>)
Rng operator()(Rng && rng, range_difference_t<Rng> const step) const
{
using I = iterator_t<Rng>;
using S = sentinel_t<Rng>;
RANGES_EXPECT(0 < step);
if(1 < step)
{
I first = ranges::begin(rng);
S const last = ranges::end(rng);
if(first != last)
{
for(I i = ranges::next(++first, step - 1, last); i != last;
advance(i, step, last), ++first)
{
*first = iter_move(i);
}
}
ranges::actions::erase(rng, first, last);
}
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::stride_fn
RANGES_INLINE_VARIABLE(stride_fn, stride)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,64 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_TAKE_HPP
#define RANGES_V3_ACTION_TAKE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct take_fn
{
template(typename Int)(
requires detail::integer_like_<Int>)
constexpr auto operator()(Int n) const
{
return make_action_closure(bind_back(take_fn{}, n));
}
template(typename Rng)(
requires forward_range<Rng> AND
erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>>)
Rng operator()(Rng && rng, range_difference_t<Rng> n) const
{
RANGES_EXPECT(n >= 0);
ranges::actions::erase(
rng, ranges::next(begin(rng), n, end(rng)), end(rng));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::take_fn
RANGES_INLINE_VARIABLE(take_fn, take)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,64 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_TAKE_WHILE_HPP
#define RANGES_V3_ACTION_TAKE_WHILE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/algorithm/find_if_not.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct take_while_fn
{
template(typename Fun)(
requires (!range<Fun>))
constexpr auto operator()(Fun fun) const
{
return make_action_closure(bind_back(take_while_fn{}, std::move(fun)));
}
template(typename Rng, typename Fun)(
requires forward_range<Rng> AND
erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>> AND
indirect_unary_predicate<Fun, iterator_t<Rng>>)
Rng operator()(Rng && rng, Fun fun) const
{
ranges::actions::erase(
rng, find_if_not(begin(rng), end(rng), std::move(fun)), end(rng));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::take_while_fn
RANGES_INLINE_VARIABLE(take_while_fn, take_while)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,65 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_TRANSFORM_HPP
#define RANGES_V3_ACTION_TRANSFORM_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/algorithm/transform.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct transform_fn
{
template(typename F, typename P = identity)(
requires (!range<F>))
constexpr auto operator()(F fun, P proj = P{}) const
{
return make_action_closure(
bind_back(transform_fn{}, std::move(fun), std::move(proj)));
}
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND copy_constructible<F> AND
indirectly_writable<
iterator_t<Rng>,
indirect_result_t<F &, projected<iterator_t<Rng>, P>>>)
Rng operator()(Rng && rng, F fun, P proj = P{}) const
{
ranges::transform(rng, begin(rng), std::move(fun), std::move(proj));
return static_cast<Rng &&>(rng);
}
};
/// \relates actions::transform_fn
RANGES_INLINE_VARIABLE(transform_fn, transform)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,68 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_UNIQUE_HPP
#define RANGES_V3_ACTION_UNIQUE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/algorithm/unique.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct unique_fn
{
template(typename C, typename P = identity)(
requires (!range<C>))
constexpr auto operator()(C pred, P proj = P{}) const
{
return make_action_closure(
bind_back(unique_fn{}, std::move(pred), std::move(proj)));
}
template(typename Rng, typename C = equal_to, typename P = identity)(
requires forward_range<Rng> AND
erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>> AND
sortable<iterator_t<Rng>, C, P>)
Rng operator()(Rng && rng, C pred = C{}, P proj = P{}) const
{
auto it = ranges::unique(rng, std::move(pred), std::move(proj));
ranges::erase(rng, it, end(rng));
return static_cast<Rng &&>(rng);
}
};
/// \relates detail::unique_fn
/// \sa action_closure
RANGES_INLINE_VARIABLE(action_closure<unique_fn>, unique)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,73 @@
/// \file
// Range v3 library
//
// Copyright Andrey Diduh 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ACTION_UNSTABLE_REMOVE_IF_HPP
#define RANGES_V3_ACTION_UNSTABLE_REMOVE_IF_HPP
#include <utility>
#include <concepts/concepts.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/action/action.hpp>
#include <range/v3/action/erase.hpp>
#include <range/v3/algorithm/unstable_remove_if.hpp>
#include <range/v3/functional/bind_back.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-actions
/// @{
namespace actions
{
struct unstable_remove_if_fn
{
template(typename C, typename P = identity)(
requires (!range<C>))
constexpr auto operator()(C pred, P proj = P{}) const
{
return make_action_closure(
bind_back(unstable_remove_if_fn{}, std::move(pred), std::move(proj)));
}
template(typename Rng, typename C, typename P = identity)(
requires bidirectional_range<Rng> AND common_range<Rng> AND
permutable<iterator_t<Rng>> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
erasable_range<Rng, iterator_t<Rng>, iterator_t<Rng>>)
Rng operator()(Rng && rng, C pred, P proj = P{}) const
{
auto it = ranges::unstable_remove_if(ranges::begin(rng),
ranges::end(rng),
std::move(pred),
std::move(proj));
ranges::erase(rng, it, ranges::end(rng));
return static_cast<Rng &&>(rng);
}
};
/// \sa `actions::unstable_remove_if_fn`
RANGES_INLINE_VARIABLE(unstable_remove_if_fn, unstable_remove_if)
} // namespace actions
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGES_V3_ACTION_UNSTABLE_REMOVE_IF_HPP

View File

@@ -0,0 +1,106 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_HPP
#define RANGES_V3_ALGORITHM_HPP
#include <range/v3/algorithm/adjacent_find.hpp>
#include <range/v3/algorithm/adjacent_remove_if.hpp>
#include <range/v3/algorithm/all_of.hpp>
#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/algorithm/binary_search.hpp>
#include <range/v3/algorithm/contains.hpp>
#include <range/v3/algorithm/copy.hpp>
#include <range/v3/algorithm/copy_backward.hpp>
#include <range/v3/algorithm/copy_if.hpp>
#include <range/v3/algorithm/copy_n.hpp>
#include <range/v3/algorithm/count.hpp>
#include <range/v3/algorithm/count_if.hpp>
#include <range/v3/algorithm/ends_with.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/algorithm/equal_range.hpp>
#include <range/v3/algorithm/fill.hpp>
#include <range/v3/algorithm/fill_n.hpp>
#include <range/v3/algorithm/find.hpp>
#include <range/v3/algorithm/find_end.hpp>
#include <range/v3/algorithm/find_first_of.hpp>
#include <range/v3/algorithm/find_if.hpp>
#include <range/v3/algorithm/find_if_not.hpp>
#include <range/v3/algorithm/fold.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/algorithm/for_each_n.hpp>
#include <range/v3/algorithm/generate.hpp>
#include <range/v3/algorithm/generate_n.hpp>
#include <range/v3/algorithm/heap_algorithm.hpp>
#include <range/v3/algorithm/inplace_merge.hpp>
#include <range/v3/algorithm/is_partitioned.hpp>
#include <range/v3/algorithm/is_sorted.hpp>
#include <range/v3/algorithm/is_sorted_until.hpp>
#include <range/v3/algorithm/lexicographical_compare.hpp>
#include <range/v3/algorithm/lower_bound.hpp>
#include <range/v3/algorithm/max.hpp>
#include <range/v3/algorithm/max_element.hpp>
#include <range/v3/algorithm/merge.hpp>
#include <range/v3/algorithm/min.hpp>
#include <range/v3/algorithm/min_element.hpp>
#include <range/v3/algorithm/minmax.hpp>
#include <range/v3/algorithm/minmax_element.hpp>
#include <range/v3/algorithm/mismatch.hpp>
#include <range/v3/algorithm/move.hpp>
#include <range/v3/algorithm/move_backward.hpp>
#include <range/v3/algorithm/none_of.hpp>
#include <range/v3/algorithm/nth_element.hpp>
#include <range/v3/algorithm/partial_sort.hpp>
#include <range/v3/algorithm/partial_sort_copy.hpp>
#include <range/v3/algorithm/partition.hpp>
#include <range/v3/algorithm/partition_copy.hpp>
#include <range/v3/algorithm/partition_point.hpp>
#include <range/v3/algorithm/permutation.hpp>
#include <range/v3/algorithm/remove.hpp>
#include <range/v3/algorithm/remove_copy.hpp>
#include <range/v3/algorithm/remove_copy_if.hpp>
#include <range/v3/algorithm/remove_if.hpp>
#include <range/v3/algorithm/replace.hpp>
#include <range/v3/algorithm/replace_copy.hpp>
#include <range/v3/algorithm/replace_copy_if.hpp>
#include <range/v3/algorithm/replace_if.hpp>
#include <range/v3/algorithm/reverse.hpp>
#include <range/v3/algorithm/reverse_copy.hpp>
#include <range/v3/algorithm/rotate.hpp>
#include <range/v3/algorithm/rotate_copy.hpp>
#include <range/v3/algorithm/sample.hpp>
#include <range/v3/algorithm/search.hpp>
#include <range/v3/algorithm/search_n.hpp>
#include <range/v3/algorithm/set_algorithm.hpp>
#include <range/v3/algorithm/shuffle.hpp>
#include <range/v3/algorithm/sort.hpp>
#include <range/v3/algorithm/stable_partition.hpp>
#include <range/v3/algorithm/stable_sort.hpp>
#include <range/v3/algorithm/starts_with.hpp>
#include <range/v3/algorithm/swap_ranges.hpp>
#include <range/v3/algorithm/transform.hpp>
#include <range/v3/algorithm/unique.hpp>
#include <range/v3/algorithm/unique_copy.hpp>
#include <range/v3/algorithm/unstable_remove_if.hpp>
#include <range/v3/algorithm/upper_bound.hpp>
#include <range/v3/detail/config.hpp>
// BUGBUG
#include <range/v3/algorithm/aux_/equal_range_n.hpp>
#include <range/v3/algorithm/aux_/lower_bound_n.hpp>
#include <range/v3/algorithm/aux_/merge_n.hpp>
#include <range/v3/algorithm/aux_/merge_n_with_buffer.hpp>
#include <range/v3/algorithm/aux_/sort_n_with_buffer.hpp>
#include <range/v3/algorithm/aux_/upper_bound_n.hpp>
#endif

View File

@@ -0,0 +1,75 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_ADJACENT_FIND_HPP
#define RANGES_V3_ALGORITHM_ADJACENT_FIND_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(adjacent_find)
/// \brief function template \c adjacent_find
///
/// range-based version of the \c adjacent_find std algorithm
///
/// \pre `Rng` is a model of the `range` concept
/// \pre `C` is a model of the `BinaryPredicate` concept
template(typename I, typename S, typename C = equal_to, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_relation<C, projected<I, P>>)
constexpr I RANGES_FUNC(adjacent_find)(I first, S last, C pred = C{}, P proj = P{})
{
if(first == last)
return first;
auto inext = first;
for(; ++inext != last; first = inext)
if(invoke(pred, invoke(proj, *first), invoke(proj, *inext)))
return first;
return inext;
}
/// \overload
template(typename Rng, typename C = equal_to, typename P = identity)(
requires forward_range<Rng> AND
indirect_relation<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(adjacent_find)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(adjacent_find)
namespace cpp20
{
using ranges::adjacent_find;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGE_ALGORITHM_ADJACENT_FIND_HPP

View File

@@ -0,0 +1,92 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler
// Copyright Christopher Di Bella
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP
#define RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP
#include <functional>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/adjacent_find.hpp>
#include <range/v3/algorithm/move.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/move.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(adjacent_remove_if)
/// \brief function \c adjacent_remove_if
///
/// range-based version of the \c adjacent_remove_if algorithm
///
/// \pre `Rng` is a model of the `forward_range` concept.
/// \pre `Pred` is a model of the `BinaryPredicate` concept.
template(typename I, typename S, typename Pred, typename Proj = identity)(
requires permutable<I> AND sentinel_for<S, I> AND
indirect_relation<Pred, projected<I, Proj>>)
constexpr I RANGES_FUNC(adjacent_remove_if)(I first, S last, Pred pred = {}, Proj proj = {})
{
first = adjacent_find(std::move(first), last, ranges::ref(pred), ranges::ref(proj));
if(first == last)
return first;
auto i = first;
for(auto j = ++i; ++j != last; ++i)
{
if(!invoke(pred, invoke(proj, *i), invoke(proj, *j)))
{
*first = iter_move(i);
++first;
}
}
*first = iter_move(i);
++first;
return first;
}
/// \overload
template(typename Rng, typename Pred, typename Proj = identity)(
requires forward_range<Rng> AND
indirect_relation<Pred, projected<iterator_t<Rng>, Proj>> AND
permutable<iterator_t<Rng>>)
constexpr borrowed_iterator_t<Rng>
RANGES_FUNC(adjacent_remove_if)(Rng && rng, Pred pred, Proj proj = {}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(adjacent_remove_if)
namespace cpp20
{
using ranges::adjacent_remove_if;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGES_V3_ALGORITHM_ADJACENT_REMOVE_IF_HPP

View File

@@ -0,0 +1,69 @@
/// \file
// Range v3 library
//
// Copyright Andrew Sutton 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_ALL_OF_HPP
#define RANGES_V3_ALGORITHM_ALL_OF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(all_of)
/// \brief function template \c all_of
template(typename I, typename S, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<F, projected<I, P>>)
constexpr bool RANGES_FUNC(all_of)(I first, S last, F pred, P proj = P{}) //
{
for(; first != last; ++first)
if(!invoke(pred, invoke(proj, *first)))
break;
return first == last;
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(all_of)(Rng && rng, F pred, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(all_of)
namespace cpp20
{
using ranges::all_of;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,70 @@
/// \file
// Range v3 library
//
// Copyright Andrew Sutton 2014
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_ANY_OF_HPP
#define RANGES_V3_ALGORITHM_ANY_OF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(any_of)
/// \brief function template \c any_of
template(typename I, typename S, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<F, projected<I, P>>)
constexpr bool RANGES_FUNC(any_of)(I first, S last, F pred, P proj = P{}) //
{
for(; first != last; ++first)
if(invoke(pred, invoke(proj, *first)))
return true;
return false;
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(any_of)(Rng && rng, F pred, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(any_of)
namespace cpp20
{
using ranges::any_of;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,92 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_EQUAL_RANGE_N_HPP
#define RANGES_V3_ALGORITHM_AUX_EQUAL_RANGE_N_HPP
#include <functional>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/lower_bound_n.hpp>
#include <range/v3/algorithm/aux_/upper_bound_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/functional/reference_wrapper.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/subrange.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct equal_range_n_fn
{
template(typename I, typename V, typename R = less, typename P = identity)(
requires forward_iterator<I> AND
indirect_strict_weak_order<R, V const *, projected<I, P>>)
constexpr subrange<I> operator()(I first,
iter_difference_t<I> dist,
V const & val,
R pred = R{},
P proj = P{}) const
{
if(0 < dist)
{
do
{
auto half = dist / 2;
auto middle = ranges::next(first, half);
auto && v = *middle;
auto && pv = invoke(proj, (decltype(v) &&)v);
if(invoke(pred, pv, val))
{
first = std::move(++middle);
dist -= half + 1;
}
else if(invoke(pred, val, pv))
{
dist = half;
}
else
{
return {lower_bound_n(std::move(first),
half,
val,
ranges::ref(pred),
ranges::ref(proj)),
upper_bound_n(ranges::next(middle),
dist - (half + 1),
val,
ranges::ref(pred),
ranges::ref(proj))};
}
} while(0 != dist);
}
return {first, first};
}
};
RANGES_INLINE_VARIABLE(equal_range_n_fn, equal_range_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,82 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_LOWER_BOUND_N_HPP
#define RANGES_V3_ALGORITHM_AUX_LOWER_BOUND_N_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/partition_point_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
// [&](auto&& i){ return invoke(pred, i, val); }
template<typename Pred, typename Val>
struct lower_bound_predicate
{
Pred & pred_;
Val & val_;
template<typename T>
constexpr bool operator()(T && t) const
{
return invoke(pred_, static_cast<T &&>(t), val_);
}
};
template<typename Pred, typename Val>
constexpr lower_bound_predicate<Pred, Val> make_lower_bound_predicate(Pred & pred,
Val & val)
{
return {pred, val};
}
} // namespace detail
/// \endcond
namespace aux
{
struct lower_bound_n_fn
{
template(typename I, typename V, typename C = less, typename P = identity)(
requires forward_iterator<I> AND
indirect_strict_weak_order<C, V const *, projected<I, P>>)
constexpr I operator()(I first,
iter_difference_t<I> d,
V const & val,
C pred = C{},
P proj = P{}) const
{
return partition_point_n(std::move(first),
d,
detail::make_lower_bound_predicate(pred, val),
std::move(proj));
}
};
RANGES_INLINE_VARIABLE(lower_bound_n_fn, lower_bound_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,115 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
//
// Algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef RANGES_V3_ALGORITHM_AUX_MERGE_N_HPP
#define RANGES_V3_ALGORITHM_AUX_MERGE_N_HPP
#include <tuple>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/copy_n.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
template<typename I0, typename I1, typename O>
using merge_n_result = detail::in1_in2_out_result<I0, I1, O>;
struct merge_n_fn
{
template(typename I0, typename I1, typename O, typename C = less,
typename P0 = identity, typename P1 = identity)(
requires mergeable<I0, I1, O, C, P0, P1>)
merge_n_result<I0, I1, O> operator()(I0 begin0,
iter_difference_t<I0> n0,
I1 begin1,
iter_difference_t<I1> n1,
O out,
C r = C{},
P0 p0 = P0{},
P1 p1 = P1{}) const
{
using T = merge_n_result<I0, I1, O>;
auto n0orig = n0;
auto n1orig = n1;
auto b0 = uncounted(begin0);
auto b1 = uncounted(begin1);
while(true)
{
if(0 == n0)
{
auto res = copy_n(b1, n1, out);
begin0 = recounted(begin0, b0, n0orig);
begin1 = recounted(begin1, res.in, n1orig);
return T{begin0, begin1, res.out};
}
if(0 == n1)
{
auto res = copy_n(b0, n0, out);
begin0 = recounted(begin0, res.in, n0orig);
begin1 = recounted(begin1, b1, n1orig);
return T{begin0, begin1, res.out};
}
if(invoke(r, invoke(p1, *b1), invoke(p0, *b0)))
{
*out = *b1;
++b1;
++out;
--n1;
}
else
{
*out = *b0;
++b0;
++out;
--n0;
}
}
}
};
RANGES_INLINE_VARIABLE(merge_n_fn, merge_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,74 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
//
// Algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef RANGES_V3_ALGORITHM_AUX_MERGE_N_WITH_BUFFER_HPP
#define RANGES_V3_ALGORITHM_AUX_MERGE_N_WITH_BUFFER_HPP
#include <tuple>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/merge_n.hpp>
#include <range/v3/algorithm/copy_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct merge_n_with_buffer_fn
{
template(typename I, typename B, typename C = less, typename P = identity)(
requires same_as<iter_common_reference_t<I>,
iter_common_reference_t<B>> AND
indirectly_copyable<I, B> AND mergeable<B, I, I, C, P, P>)
I operator()(I begin0,
iter_difference_t<I> n0,
I begin1,
iter_difference_t<I> n1,
B buff,
C r = C{},
P p = P{}) const
{
copy_n(begin0, n0, buff);
return merge_n(buff, n0, begin1, n1, begin0, r, p, p).out;
}
};
RANGES_INLINE_VARIABLE(merge_n_with_buffer_fn, merge_n_with_buffer)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,65 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_PARTITION_POINT_N_HPP
#define RANGES_V3_ALGORITHM_AUX_PARTITION_POINT_N_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct partition_point_n_fn
{
template(typename I, typename C, typename P = identity)(
requires forward_iterator<I> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr I operator()(I first,
iter_difference_t<I> d,
C pred,
P proj = P{}) const //
{
if(0 < d)
{
do
{
auto half = d / 2;
auto middle = next(uncounted(first), half);
if(invoke(pred, invoke(proj, *middle)))
{
first = recounted(first, std::move(++middle), half + 1);
d -= half + 1;
}
else
d = half;
} while(0 != d);
}
return first;
}
};
RANGES_INLINE_VARIABLE(partition_point_n_fn, partition_point_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,73 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
//
// Algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef RANGES_V3_ALGORITHM_AUX_SORT_N_WITH_BUFFER_HPP
#define RANGES_V3_ALGORITHM_AUX_SORT_N_WITH_BUFFER_HPP
#include <tuple>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/merge_n_with_buffer.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct sort_n_with_buffer_fn
{
template(typename I, typename B, typename C = less, typename P = identity)(
requires same_as<iter_common_reference_t<I>,
iter_common_reference_t<B>> AND
indirectly_copyable<I, B> AND mergeable<B, I, I, C, P, P>)
I operator()(I first, iter_difference_t<I> n, B buff, C r = C{}, P p = P{})
const
{
auto half = n / 2;
if(0 == half)
return next(first, n);
I m = (*this)(first, half, buff, r, p);
(*this)(m, n - half, buff, r, p);
return merge_n_with_buffer(first, half, m, n - half, buff, r, p);
}
};
RANGES_INLINE_VARIABLE(sort_n_with_buffer_fn, sort_n_with_buffer)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,87 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_UPPER_BOUND_N_HPP
#define RANGES_V3_ALGORITHM_AUX_UPPER_BOUND_N_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/partition_point_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
// [&](auto&& i){ return !invoke(pred, val, i); }
template<typename Pred, typename Val>
struct upper_bound_predicate
{
Pred & pred_;
Val & val_;
template<typename T>
constexpr bool operator()(T && t) const
{
return !invoke(pred_, val_, static_cast<T &&>(t));
}
};
template<typename Pred, typename Val>
constexpr upper_bound_predicate<Pred, Val> make_upper_bound_predicate(Pred & pred,
Val & val)
{
return {pred, val};
}
} // namespace detail
/// \endcond
namespace aux
{
struct upper_bound_n_fn
{
/// \brief template function upper_bound
///
/// range-based version of the `upper_bound` std algorithm
///
/// \pre `Rng` is a model of the `range` concept
template(typename I, typename V, typename C = less, typename P = identity)(
requires forward_iterator<I> AND
indirect_strict_weak_order<C, V const *, projected<I, P>>)
constexpr I operator()(I first,
iter_difference_t<I> d,
V const & val,
C pred = C{},
P proj = P{}) const
{
return partition_point_n(std::move(first),
d,
detail::make_upper_bound_predicate(pred, val),
std::move(proj));
}
};
RANGES_INLINE_VARIABLE(upper_bound_n_fn, upper_bound_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,81 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_BINARY_SEARCH_HPP
#define RANGES_V3_ALGORITHM_BINARY_SEARCH_HPP
#include <functional>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/lower_bound.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(binary_search)
/// \brief function template \c binary_search
///
/// range-based version of the \c binary_search std algorithm
///
/// \pre `Rng` is a model of the `range` concept
template(typename I,
typename S,
typename V,
typename C = less,
typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, V const *, projected<I, P>>)
constexpr bool RANGES_FUNC(binary_search)(
I first, S last, V const & val, C pred = C{}, P proj = P{})
{
first =
lower_bound(std::move(first), last, val, ranges::ref(pred), ranges::ref(proj));
return first != last && !invoke(pred, val, invoke(proj, *first));
}
/// \overload
template(typename Rng, typename V, typename C = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<C, V const *, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(binary_search)(
Rng && rng, V const & val, C pred = C{}, P proj = P{}) //
{
static_assert(!is_infinite<Rng>::value,
"Trying to binary search an infinite range");
return (*this)(begin(rng), end(rng), val, std::move(pred), std::move(proj));
}
RANGES_FUNC_END(binary_search)
namespace cpp20
{
using ranges::binary_search;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,60 @@
/// \file
// Range v3 library
//
// Copyright Johel Guerrero 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_CONTAINS_HPP
#define RANGES_V3_ALGORITHM_CONTAINS_HPP
#include <utility>
#include <concepts/concepts.hpp>
#include <range/v3/algorithm/find.hpp>
#include <range/v3/detail/config.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(contains)
/// \brief function template \c contains
template(typename I, typename S, typename T, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_relation<equal_to, projected<I, P>, const T *>)
constexpr bool RANGES_FUNC(contains)(I first, S last, const T & val, P proj = {})
{
return find(std::move(first), last, val, std::move(proj)) != last;
}
/// \overload
template(typename Rng, typename T, typename P = identity)(
requires input_range<Rng> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, const T *>)
constexpr bool RANGES_FUNC(contains)(Rng && rng, const T & val, P proj = {})
{
return (*this)(begin(rng), end(rng), val, std::move(proj));
}
RANGES_FUNC_END(contains)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGES_V3_ALGORITHM_CONTAINS_HPP

View File

@@ -0,0 +1,89 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COPY_HPP
#define RANGES_V3_ALGORITHM_COPY_HPP
#include <functional>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/copy.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using copy_result = detail::in_out_result<I, O>;
RANGES_HIDDEN_DETAIL(namespace _copy CPP_PP_LBRACE())
RANGES_FUNC_BEGIN(copy)
/// \brief function template \c copy
template(typename I, typename S, typename O)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O> AND indirectly_copyable<I, O>)
constexpr copy_result<I, O> RANGES_FUNC(copy)(I first, S last, O out) //
{
for(; first != last; ++first, ++out)
*out = *first;
return {first, out};
}
/// \overload
template(typename Rng, typename O)(
requires input_range<Rng> AND weakly_incrementable<O> AND
indirectly_copyable<iterator_t<Rng>, O>)
constexpr copy_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(copy)(Rng && rng, O out) //
{
return (*this)(begin(rng), end(rng), std::move(out));
}
RANGES_FUNC_END(copy)
RANGES_HIDDEN_DETAIL(CPP_PP_RBRACE())
#ifndef RANGES_DOXYGEN_INVOKED
struct copy_fn
: aux::copy_fn
, _copy::copy_fn
{
using aux::copy_fn::operator();
using _copy::copy_fn::operator();
};
RANGES_INLINE_VARIABLE(copy_fn, copy)
#endif
namespace cpp20
{
using ranges::copy_result;
using ranges::RANGES_HIDDEN_DETAIL(_copy::) copy;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,74 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COPY_BACKWARD_HPP
#define RANGES_V3_ALGORITHM_COPY_BACKWARD_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using copy_backward_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(copy_backward)
/// \brief function template \c copy_backward
template(typename I, typename S, typename O)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
bidirectional_iterator<O> AND indirectly_copyable<I, O>)
constexpr copy_backward_result<I, O> RANGES_FUNC(copy_backward)(I first, S end_, O out)
{
I i = ranges::next(first, end_), last = i;
while(first != i)
*--out = *--i;
return {last, out};
}
/// \overload
template(typename Rng, typename O)(
requires bidirectional_range<Rng> AND bidirectional_iterator<O> AND
indirectly_copyable<iterator_t<Rng>, O>)
copy_backward_result<borrowed_iterator_t<Rng>, O> //
constexpr RANGES_FUNC(copy_backward)(Rng && rng, O out)
{
return (*this)(begin(rng), end(rng), std::move(out));
}
RANGES_FUNC_END(copy_backward)
namespace cpp20
{
using ranges::copy_backward;
using ranges::copy_backward_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,88 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COPY_IF_HPP
#define RANGES_V3_ALGORITHM_COPY_IF_HPP
#include <functional>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using copy_if_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(copy_if)
/// \brief function template \c copy_if
template(typename I, typename S, typename O, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O> AND
indirect_unary_predicate<F, projected<I, P>> AND
indirectly_copyable<I, O>)
constexpr copy_if_result<I, O> //
RANGES_FUNC(copy_if)(I first, S last, O out, F pred, P proj = P{}) //
{
for(; first != last; ++first)
{
auto && x = *first;
if(invoke(pred, invoke(proj, x)))
{
*out = (decltype(x) &&)x;
++out;
}
}
return {first, out};
}
/// \overload
template(typename Rng, typename O, typename F, typename P = identity)(
requires input_range<Rng> AND weakly_incrementable<O> AND
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>> AND
indirectly_copyable<iterator_t<Rng>, O>)
constexpr copy_if_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(copy_if)(Rng && rng, O out, F pred, P proj = P{})
{
return (*this)(
begin(rng), end(rng), std::move(out), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(copy_if)
namespace cpp20
{
using ranges::copy_if;
using ranges::copy_if_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,69 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COPY_N_HPP
#define RANGES_V3_ALGORITHM_COPY_N_HPP
#include <functional>
#include <tuple>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using copy_n_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(copy_n)
/// \brief function template \c copy_n
template(typename I, typename O, typename P = identity)(
requires input_iterator<I> AND weakly_incrementable<O> AND
indirectly_copyable<I, O>)
constexpr copy_n_result<I, O> RANGES_FUNC(copy_n)(I first, iter_difference_t<I> n, O out)
{
RANGES_EXPECT(0 <= n);
auto norig = n;
auto b = uncounted(first);
for(; n != 0; ++b, ++out, --n)
*out = *b;
return {recounted(first, b, norig), out};
}
RANGES_FUNC_END(copy_n)
namespace cpp20
{
using ranges::copy_n;
using ranges::copy_n_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,72 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COUNT_HPP
#define RANGES_V3_ALGORITHM_COUNT_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(count)
/// \brief function template \c count
template(typename I, typename S, typename V, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_relation<equal_to, projected<I, P>, V const *>)
constexpr iter_difference_t<I> //
RANGES_FUNC(count)(I first, S last, V const & val, P proj = P{})
{
iter_difference_t<I> n = 0;
for(; first != last; ++first)
if(invoke(proj, *first) == val)
++n;
return n;
}
/// \overload
template(typename Rng, typename V, typename P = identity)(
requires input_range<Rng> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, V const *>)
constexpr iter_difference_t<iterator_t<Rng>> //
RANGES_FUNC(count)(Rng && rng, V const & val, P proj = P{})
{
return (*this)(begin(rng), end(rng), val, std::move(proj));
}
RANGES_FUNC_END(count)
namespace cpp20
{
using ranges::count;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,71 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COUNT_IF_HPP
#define RANGES_V3_ALGORITHM_COUNT_IF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(count_if)
/// \brief function template \c count_if
template(typename I, typename S, typename R, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<R, projected<I, P>>)
constexpr iter_difference_t<I> RANGES_FUNC(count_if)(I first, S last, R pred, P proj = P{})
{
iter_difference_t<I> n = 0;
for(; first != last; ++first)
if(invoke(pred, invoke(proj, *first)))
++n;
return n;
}
/// \overload
template(typename Rng, typename R, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<R, projected<iterator_t<Rng>, P>>)
constexpr iter_difference_t<iterator_t<Rng>> //
RANGES_FUNC(count_if)(Rng && rng, R pred, P proj = P{})
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(count_if)
namespace cpp20
{
using ranges::count_if;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,100 @@
/// \file
// Range v3 library
//
// Copyright Johel Guerrero 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_ENDS_WITH_HPP
#define RANGES_V3_ALGORITHM_ENDS_WITH_HPP
#include <utility>
#include <concepts/concepts.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/detail/config.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(ends_with)
/// \brief function template \c ends_with
template(typename I0,
typename S0,
typename I1,
typename S1,
typename C = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires ((forward_iterator<I0> && sentinel_for<S0, I0>) ||
(input_iterator<I0> && sized_sentinel_for<S0, I0>)) AND
((forward_iterator<I1> && sentinel_for<S1, I1>) ||
(input_iterator<I1> && sized_sentinel_for<S1, I1>)) AND
indirectly_comparable<I0, I1, C, P0, P1>)
constexpr bool RANGES_FUNC(ends_with)(I0 begin0,
S0 end0,
I1 begin1,
S1 end1,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{}) //
{
const auto drop = distance(begin0, end0) - distance(begin1, end1);
if(drop < 0)
return false;
return equal(next(std::move(begin0), drop),
std::move(end0),
std::move(begin1),
std::move(end1),
std::move(pred),
std::move(proj0),
std::move(proj1));
}
/// \overload
template(typename Rng0,
typename Rng1,
typename C = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires (forward_range<Rng0> || (input_range<Rng0> && sized_range<Rng0>)) AND
(forward_range<Rng1> || (input_range<Rng1> && sized_range<Rng1>)) AND
indirectly_comparable<iterator_t<Rng0>, iterator_t<Rng1>, C, P0, P1>)
constexpr bool RANGES_FUNC(ends_with)(
Rng0 && rng0, Rng1 && rng1, C pred = C{}, P0 proj0 = P0{}, P1 proj1 = P1{}) //
{
const auto drop = distance(rng0) - distance(rng1);
if(drop < 0)
return false;
return equal(next(begin(rng0), drop),
end(rng0),
begin(rng1),
end(rng1),
std::move(pred),
std::move(proj0),
std::move(proj1));
}
RANGES_FUNC_END(ends_with)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,175 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_EQUAL_HPP
#define RANGES_V3_ALGORITHM_EQUAL_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// \cond
namespace detail
{
template<typename I0, typename S0, typename I1, typename S1, typename C,
typename P0, typename P1>
constexpr bool equal_nocheck(I0 begin0, S0 end0, I1 begin1, S1 end1, C pred,
P0 proj0, P1 proj1)
{
for(; begin0 != end0 && begin1 != end1; ++begin0, ++begin1)
if(!invoke(pred, invoke(proj0, *begin0), invoke(proj1, *begin1)))
return false;
return begin0 == end0 && begin1 == end1;
}
} // namespace detail
/// \endcond
RANGES_FUNC_BEGIN(equal)
/// \brief function template \c equal
template(typename I0,
typename S0,
typename I1,
typename C = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires input_iterator<I0> AND sentinel_for<S0, I0> AND
input_iterator<I1> AND indirectly_comparable<I0, I1, C, P0, P1>)
RANGES_DEPRECATED(
"Use the variant of ranges::equal that takes an upper bound for "
"both sequences")
constexpr bool RANGES_FUNC(equal)(I0 begin0,
S0 end0,
I1 begin1,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{}) //
{
for(; begin0 != end0; ++begin0, ++begin1)
if(!invoke(pred, invoke(proj0, *begin0), invoke(proj1, *begin1)))
return false;
return true;
}
/// \overload
template(typename I0,
typename S0,
typename I1,
typename S1,
typename C = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires input_iterator<I0> AND sentinel_for<S0, I0> AND
input_iterator<I1> AND sentinel_for<S1, I1> AND
indirectly_comparable<I0, I1, C, P0, P1>)
constexpr bool RANGES_FUNC(equal)(I0 begin0,
S0 end0,
I1 begin1,
S1 end1,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{}) //
{
if(RANGES_CONSTEXPR_IF(sized_sentinel_for<S0, I0> &&
sized_sentinel_for<S1, I1>))
if(distance(begin0, end0) != distance(begin1, end1))
return false;
return detail::equal_nocheck(std::move(begin0),
std::move(end0),
std::move(begin1),
std::move(end1),
std::move(pred),
std::move(proj0),
std::move(proj1));
}
/// \overload
template(typename Rng0,
typename I1Ref,
typename C = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires input_range<Rng0> AND input_iterator<uncvref_t<I1Ref>> AND
indirectly_comparable<iterator_t<Rng0>, uncvref_t<I1Ref>, C, P0, P1>)
RANGES_DEPRECATED(
"Use the variant of ranges::equal that takes an upper bound for "
"both sequences")
constexpr bool RANGES_FUNC(equal)(Rng0 && rng0,
I1Ref && begin1,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{}) //
{
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
return (*this)(begin(rng0),
end(rng0),
(I1Ref &&) begin1,
std::move(pred),
std::move(proj0),
std::move(proj1));
RANGES_DIAGNOSTIC_POP
}
/// \overload
template(typename Rng0,
typename Rng1,
typename C = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires input_range<Rng0> AND input_range<Rng1> AND
indirectly_comparable<iterator_t<Rng0>, iterator_t<Rng1>, C, P0, P1>)
constexpr bool RANGES_FUNC(equal)(
Rng0 && rng0, Rng1 && rng1, C pred = C{}, P0 proj0 = P0{}, P1 proj1 = P1{}) //
{
if(RANGES_CONSTEXPR_IF(sized_range<Rng0> && sized_range<Rng1>))
if(distance(rng0) != distance(rng1))
return false;
return detail::equal_nocheck(begin(rng0),
end(rng0),
begin(rng1),
end(rng1),
std::move(pred),
std::move(proj0),
std::move(proj1));
}
RANGES_FUNC_END(equal)
namespace cpp20
{
using ranges::equal;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,130 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_EQUAL_RANGE_HPP
#define RANGES_V3_ALGORITHM_EQUAL_RANGE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/equal_range_n.hpp>
#include <range/v3/algorithm/aux_/lower_bound_n.hpp>
#include <range/v3/algorithm/upper_bound.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/subrange.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(equal_range)
/// \brief function template \c equal_range
template(typename I,
typename S,
typename V,
typename C = less,
typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, V const *, projected<I, P>>)
constexpr subrange<I> RANGES_FUNC(equal_range)(
I first, S last, V const & val, C pred = C{}, P proj = P{})
{
if(RANGES_CONSTEXPR_IF(sized_sentinel_for<S, I>))
{
auto const len = distance(first, last);
return aux::equal_range_n(
std::move(first), len, val, std::move(pred), std::move(proj));
}
// Probe exponentially for either end-of-range, an iterator that
// is past the equal range (i.e., denotes an element greater
// than val), or is in the equal range (denotes an element equal
// to val).
auto dist = iter_difference_t<I>{1};
while(true)
{
auto mid = first;
auto d = advance(mid, dist, last);
if(d || mid == last)
{
// at the end of the input range
dist -= d;
return aux::equal_range_n(
std::move(first), dist, val, ranges::ref(pred), ranges::ref(proj));
}
// if val < *mid, mid is after the target range.
auto && v = *mid;
auto && pv = invoke(proj, (decltype(v) &&)v);
if(invoke(pred, val, pv))
{
return aux::equal_range_n(
std::move(first), dist, val, ranges::ref(pred), ranges::ref(proj));
}
else if(!invoke(pred, pv, val))
{
// *mid == val: the lower bound is <= mid, and the upper bound is >
// mid.
return {
aux::lower_bound_n(
std::move(first), dist, val, ranges::ref(pred), ranges::ref(proj)),
upper_bound(std::move(mid),
std::move(last),
val,
ranges::ref(pred),
ranges::ref(proj))};
}
// *mid < val, mid is before the target range.
first = std::move(mid);
++first;
dist *= 2;
}
}
/// \overload
template(typename Rng, typename V, typename C = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<C, V const *, projected<iterator_t<Rng>, P>>)
constexpr borrowed_subrange_t<Rng> //
RANGES_FUNC(equal_range)(Rng && rng, V const & val, C pred = C{}, P proj = P{}) //
{
if(RANGES_CONSTEXPR_IF(sized_range<Rng>))
{
auto const len = distance(rng);
return aux::equal_range_n(
begin(rng), len, val, std::move(pred), std::move(proj));
}
return (*this)(begin(rng), end(rng), val, std::move(pred), std::move(proj));
}
RANGES_FUNC_END(equal_range)
namespace cpp20
{
using ranges::equal_range;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,62 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FILL_HPP
#define RANGES_V3_ALGORITHM_FILL_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(fill)
/// \brief function template \c fill
template(typename O, typename S, typename V)(
requires output_iterator<O, V const &> AND sentinel_for<S, O>)
constexpr O RANGES_FUNC(fill)(O first, S last, V const & val) //
{
for(; first != last; ++first)
*first = val;
return first;
}
/// \overload
template(typename Rng, typename V)(
requires output_range<Rng, V const &>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(fill)(Rng && rng, V const & val)
{
return (*this)(begin(rng), end(rng), val);
}
RANGES_FUNC_END(fill)
namespace cpp20
{
using ranges::fill;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,59 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FILL_N_HPP
#define RANGES_V3_ALGORITHM_FILL_N_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(fill_n)
/// \brief function template \c equal
template(typename O, typename V)(
requires output_iterator<O, V const &>)
constexpr O RANGES_FUNC(fill_n)(O first, iter_difference_t<O> n, V const & val)
{
RANGES_EXPECT(n >= 0);
auto norig = n;
auto b = uncounted(first);
for(; n != 0; ++b, --n)
*b = val;
return recounted(first, b, norig);
}
RANGES_FUNC_END(fill_n)
namespace cpp20
{
using ranges::fill_n;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,78 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FIND_HPP
#define RANGES_V3_ALGORITHM_FIND_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(find)
/// \brief template function \c find
///
/// range-based version of the \c find std algorithm
///
/// \pre `Rng` is a model of the `range` concept
/// \pre `I` is a model of the `input_iterator` concept
/// \pre `S` is a model of the `sentinel_for<I>` concept
/// \pre `P` is a model of the `invocable<iter_common_reference_t<I>>` concept
/// \pre The ResultType of `P` is equality_comparable with V
template(typename I, typename S, typename V, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_relation<equal_to, projected<I, P>, V const *>)
constexpr I RANGES_FUNC(find)(I first, S last, V const & val, P proj = P{})
{
for(; first != last; ++first)
if(invoke(proj, *first) == val)
break;
return first;
}
/// \overload
template(typename Rng, typename V, typename P = identity)(
requires input_range<Rng> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, V const *>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(find)(Rng && rng, V const & val, P proj = P{})
{
return (*this)(begin(rng), end(rng), val, std::move(proj));
}
RANGES_FUNC_END(find)
namespace cpp20
{
using ranges::find;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,237 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FIND_END_HPP
#define RANGES_V3_ALGORITHM_FIND_END_HPP
#include <utility>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/subrange.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
template(typename I, typename S)(
requires input_iterator<I> AND sentinel_for<S, I>)
constexpr I next_to_if(I i, S s, std::true_type)
{
return ranges::next(i, s);
}
template(typename I, typename S)(
requires input_iterator<I> AND sentinel_for<S, I>)
constexpr S next_to_if(I, S s, std::false_type)
{
return s;
}
template(bool B, typename I, typename S)(
requires input_iterator<I> AND sentinel_for<S, I>)
constexpr meta::if_c<B, I, S> next_to_if(I i, S s)
{
return detail::next_to_if(std::move(i), std::move(s), meta::bool_<B>{});
}
template<typename I1, typename S1, typename I2, typename S2, typename R,
typename P>
constexpr subrange<I1> find_end_impl(I1 begin1, S1 end1, I2 begin2, S2 end2, R pred, P proj,
std::forward_iterator_tag, std::forward_iterator_tag)
{
bool found = false;
I1 res_begin, res_end;
if(begin2 == end2)
{
auto e1 = ranges::next(begin1, end1);
return {e1, e1};
}
while(true)
{
while(true)
{
if(begin1 == end1)
return {(found ? res_begin : begin1), (found ? res_end : begin1)};
if(invoke(pred, invoke(proj, *begin1), *begin2))
break;
++begin1;
}
auto tmp1 = begin1;
auto tmp2 = begin2;
while(true)
{
if(++tmp2 == end2)
{
res_begin = begin1++;
res_end = ++tmp1;
found = true;
break;
}
if(++tmp1 == end1)
return {(found ? res_begin : tmp1), (found ? res_end : tmp1)};
if(!invoke(pred, invoke(proj, *tmp1), *tmp2))
{
++begin1;
break;
}
}
}
}
template<typename I1, typename I2, typename R, typename P>
constexpr subrange<I1> find_end_impl(I1 begin1, I1 end1, I2 begin2, I2 end2, R pred, P proj,
std::bidirectional_iterator_tag,
std::bidirectional_iterator_tag)
{
// modeled after search algorithm (in reverse)
if(begin2 == end2)
return {end1, end1}; // Everything matches an empty sequence
I1 l1 = end1;
I2 l2 = end2;
--l2;
while(true)
{
// Find end element in sequence 1 that matches *(end2-1), with a mininum
// of loop checks
do
// return {end1,end1} if no element matches *begin2
if(begin1 == l1)
return {end1, end1};
while(!invoke(pred, invoke(proj, *--l1), *l2));
// *l1 matches *l2, now match elements before here
I1 m1 = l1;
I2 m2 = l2;
do
// If pattern exhausted, {m1,++l1} is the answer
// (works for 1 element pattern)
if(m2 == begin2)
return {m1, ++l1};
// Otherwise if source exhausted, pattern not found
else if(m1 == begin1)
return {end1, end1};
// if there is a mismatch, restart with a new l1
// else there is a match, check next elements
while(invoke(pred, invoke(proj, *--m1), *--m2));
}
}
template<typename I1, typename I2, typename R, typename P>
constexpr subrange<I1> find_end_impl(I1 begin1, I1 end1, I2 begin2, I2 end2, R pred, P proj,
std::random_access_iterator_tag,
std::random_access_iterator_tag)
{
// Take advantage of knowing source and pattern lengths. Stop short when
// source is smaller than pattern
auto len2 = end2 - begin2;
if(len2 == 0)
return {end1, end1};
auto len1 = end1 - begin1;
if(len1 < len2)
return {end1, end1};
I1 const start =
begin1 + (len2 - 1); // End of pattern match can't go before here
I1 l1 = end1;
I2 l2 = end2;
--l2;
while(true)
{
do
if(start == l1)
return {end1, end1};
while(!invoke(pred, invoke(proj, *--l1), *l2));
I1 m1 = l1;
I2 m2 = l2;
do
if(m2 == begin2)
return {m1, ++l1};
// no need to check range on m1 because s guarantees we have enough source
while(invoke(pred, invoke(proj, *--m1), *--m2));
}
}
} // namespace detail
/// \endcond
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(find_end)
/// \brief function template \c find_end
template(typename I1,
typename S1,
typename I2,
typename S2,
typename R = equal_to,
typename P = identity)(
requires forward_iterator<I1> AND sentinel_for<S1, I1> AND
forward_iterator<I2> AND sentinel_for<S2, I2> AND
indirect_relation<R, projected<I1, P>, I2>)
constexpr subrange<I1> RANGES_FUNC(find_end)(
I1 begin1, S1 end1, I2 begin2, S2 end2, R pred = R{}, P proj = P{}) //
{
constexpr bool Bidi =
bidirectional_iterator<I1> && bidirectional_iterator<I2>;
return detail::find_end_impl(begin1,
detail::next_to_if<Bidi>(begin1, end1),
begin2,
detail::next_to_if<Bidi>(begin2, end2),
std::move(pred),
std::move(proj),
iterator_tag_of<I1>(),
iterator_tag_of<I2>());
}
/// \overload
template(typename Rng1,
typename Rng2,
typename R = equal_to,
typename P = identity)(
requires forward_range<Rng1> AND forward_range<Rng2> AND
indirect_relation<R, projected<iterator_t<Rng1>, P>, iterator_t<Rng2>>)
constexpr borrowed_subrange_t<Rng1> RANGES_FUNC(find_end)(
Rng1 && rng1, Rng2 && rng2, R pred = R{}, P proj = P{}) //
{
return (*this)(begin(rng1),
end(rng1),
begin(rng2),
end(rng2),
std::move(pred),
std::move(proj));
}
RANGES_FUNC_END(find_end)
namespace cpp20
{
using ranges::find_end;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,103 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FIND_FIRST_OF_HPP
#define RANGES_V3_ALGORITHM_FIND_FIRST_OF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(find_first_of)
// Rationale: return I0 instead of pair<I0,I1> because find_first_of need
// not actually compute the end of [I1,S0); therefore, it is not necessarily
// losing information. E.g., if begin0 == end0, we can return begin0 immediately.
// If we returned pair<I0,I1>, we would need to do an O(N) scan to find the
// end position.
/// \brief function template \c find_first_of
template(typename I0,
typename S0,
typename I1,
typename S1,
typename R = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires input_iterator<I0> AND sentinel_for<S0, I0> AND
forward_iterator<I1> AND sentinel_for<S1, I1> AND
indirect_relation<R, projected<I0, P0>, projected<I1, P1>>)
constexpr I0 RANGES_FUNC(find_first_of)(I0 begin0,
S0 end0,
I1 begin1,
S1 end1,
R pred = R{},
P0 proj0 = P0{},
P1 proj1 = P1{}) //
{
for(; begin0 != end0; ++begin0)
for(auto tmp = begin1; tmp != end1; ++tmp)
if(invoke(pred, invoke(proj0, *begin0), invoke(proj1, *tmp)))
return begin0;
return begin0;
}
/// \overload
template(typename Rng0,
typename Rng1,
typename R = equal_to,
typename P0 = identity,
typename P1 = identity)(
requires input_range<Rng0> AND forward_range<Rng1> AND
indirect_relation<R,
projected<iterator_t<Rng0>, P0>,
projected<iterator_t<Rng1>, P1>>)
constexpr borrowed_iterator_t<Rng0> RANGES_FUNC(find_first_of)(
Rng0 && rng0, Rng1 && rng1, R pred = R{}, P0 proj0 = P0{}, P1 proj1 = P1{}) //
{
return (*this)(begin(rng0),
end(rng0),
begin(rng1),
end(rng1),
std::move(pred),
std::move(proj0),
std::move(proj1));
}
RANGES_FUNC_END(find_first_of)
namespace cpp20
{
using ranges::find_first_of;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,79 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FIND_IF_HPP
#define RANGES_V3_ALGORITHM_FIND_IF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(find_if)
/// \brief template function \c find
///
/// range-based version of the \c find std algorithm
///
/// \pre `Rng` is a model of the `range` concept
/// \pre `I` is a model of the `input_iterator` concept
/// \pre `S` is a model of the `sentinel_for<I>` concept
/// \pre `P` is a model of the `invocable<V>` concept, where `V` is the
/// value type of I.
/// \pre `F` models `predicate<X>`, where `X` is the result type
/// of `invocable<P, V>`
template(typename I, typename S, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<F, projected<I, P>>)
constexpr I RANGES_FUNC(find_if)(I first, S last, F pred, P proj = P{})
{
for(; first != last; ++first)
if(invoke(pred, invoke(proj, *first)))
break;
return first;
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(find_if)(Rng && rng, F pred, P proj = P{})
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(find_if)
namespace cpp20
{
using ranges::find_if;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,80 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FIND_IF_NOT_HPP
#define RANGES_V3_ALGORITHM_FIND_IF_NOT_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(find_if_not)
/// \brief template function \c find_if_not
///
/// range-based version of the \c find_if_not std algorithm
///
/// \pre `Rng` is a model of the `range` concept
/// \pre `I` is a model of the `input_iterator` concept
/// \pre `S` is a model of the `sentinel_for<I>` concept
/// \pre `P` is a model of the `invocable<V>` concept, where `V` is the
/// value type of I.
/// \pre `F` models `predicate<X>`, where `X` is the result type
/// of `invocable<P, V>`
template(typename I, typename S, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<F, projected<I, P>>)
constexpr I RANGES_FUNC(find_if_not)(I first, S last, F pred, P proj = P{})
{
for(; first != last; ++first)
if(!invoke(pred, invoke(proj, *first)))
break;
return first;
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(find_if_not)(Rng && rng, F pred, P proj = P{})
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(find_if_not)
namespace cpp20
{
using ranges::find_if_not;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,19 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2021-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#ifndef RANGES_V3_ALGORITHM_FOLD_HPP
#define RANGES_V3_ALGORITHM_FOLD_HPP
#include <range/v3/algorithm/fold_left.hpp>
#include <range/v3/algorithm/fold_right.hpp>
#endif

View File

@@ -0,0 +1,125 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2021-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#ifndef RANGES_V3_ALGORITHM_FOLD_LEFT_HPP
#define RANGES_V3_ALGORITHM_FOLD_LEFT_HPP
#include <meta/meta.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/utility/optional.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
// clang-format off
/// \concept indirectly_binary_left_foldable_impl
/// \brief The \c indirectly_binary_left_foldable_impl concept
template<class F, class T, class I, class U>
CPP_concept indirectly_binary_left_foldable_impl =
movable<T> &&
movable<U> &&
convertible_to<T, U> &&
invocable<F&, U, iter_reference_t<I>> &&
assignable_from<U&, invoke_result_t<F&, U, iter_reference_t<I>>>;
/// \concept indirectly_binary_left_foldable
/// \brief The \c indirectly_binary_left_foldable concept
template<class F, class T, class I>
CPP_concept indirectly_binary_left_foldable =
copy_constructible<F> &&
indirectly_readable<I> &&
invocable<F&, T, iter_reference_t<I>> &&
convertible_to<invoke_result_t<F&, T, iter_reference_t<I>>,
std::decay_t<invoke_result_t<F&, T, iter_reference_t<I>>>> &&
indirectly_binary_left_foldable_impl<F, T, I, std::decay_t<invoke_result_t<F&, T, iter_reference_t<I>>>>;
// clang-format on
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(fold_left)
template(typename I, typename S, typename T, typename Op)(
requires sentinel_for<S, I> AND input_iterator<I> AND
indirectly_binary_left_foldable<Op, T, I>) //
constexpr auto
RANGES_FUNC(fold_left)(I first, S last, T init, Op op)
{
using U = std::decay_t<invoke_result_t<Op &, T, iter_reference_t<I>>>;
if(first == last)
{
return U(std::move(init));
}
U accum = invoke(op, std::move(init), *first);
for(++first; first != last; ++first)
{
accum = invoke(op, std::move(accum), *first);
}
return accum;
}
template(typename Rng, typename T, typename Op)(
requires input_range<Rng> AND
indirectly_binary_left_foldable<Op, T, iterator_t<Rng>>) //
constexpr auto
RANGES_FUNC(fold_left)(Rng && rng, T init, Op op)
{
return (*this)(begin(rng), end(rng), std::move(init), std::move(op));
}
RANGES_FUNC_END(fold_left)
RANGES_FUNC_BEGIN(fold_left_first)
template(typename I, typename S, typename Op)(
requires sentinel_for<S, I> AND input_iterator<I> AND
indirectly_binary_left_foldable<Op, iter_value_t<I>, I>
AND constructible_from<iter_value_t<I>, iter_reference_t<I>>) //
constexpr auto
RANGES_FUNC(fold_left_first)(I first, S last, Op op)
{
using U = invoke_result_t<fold_left_fn, I, S, iter_value_t<I>, Op>;
if(first == last)
{
return optional<U>();
}
iter_value_t<I> init = *first;
++first;
return optional<U>(
in_place,
fold_left_fn{}(std::move(first), std::move(last), std::move(init), op));
}
template(typename R, typename Op)(
requires input_range<R> AND
indirectly_binary_left_foldable<Op, range_value_t<R>, iterator_t<R>>
AND constructible_from<range_value_t<R>, range_reference_t<R>>) //
constexpr auto
RANGES_FUNC(fold_left_first)(R && rng, Op op)
{
return (*this)(begin(rng), end(rng), std::move(op));
}
RANGES_FUNC_END(fold_left_first)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,126 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2021-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#ifndef RANGES_V3_ALGORITHM_FOLD_RIGHT_HPP
#define RANGES_V3_ALGORITHM_FOLD_RIGHT_HPP
#include <meta/meta.hpp>
#include <range/v3/algorithm/fold_left.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/utility/optional.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace detail
{
template<typename F>
struct flipped
{
F f;
template(class T, class U)(requires invocable<F &, U, T>) //
invoke_result_t<F &, U, T>
operator()(T &&, U &&);
};
} // namespace detail
// clang-format off
/// \concept indirectly_binary_right_foldable
/// \brief The \c indirectly_binary_right_foldable concept
template<class F, class T, class I>
CPP_concept indirectly_binary_right_foldable =
indirectly_binary_left_foldable<detail::flipped<F>, T, I>;
// clang-format on
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(fold_right)
template(typename I, typename S, typename T, typename Op)(
requires sentinel_for<S, I> AND bidirectional_iterator<I> AND
indirectly_binary_right_foldable<Op, T, I>) //
constexpr auto
RANGES_FUNC(fold_right)(I first, S last, T init, Op op)
{
using U = std::decay_t<invoke_result_t<Op &, iter_reference_t<I>, T>>;
if(first == last)
{
return U(std::move(init));
}
I tail = next(first, last);
U accum = invoke(op, *--tail, std::move(init));
while(first != tail)
{
accum = invoke(op, *--tail, std::move(accum));
}
return accum;
}
template(typename Rng, typename T, typename Op)(
requires bidirectional_range<Rng> AND
indirectly_binary_right_foldable<Op, T, iterator_t<Rng>>) //
constexpr auto
RANGES_FUNC(fold_right)(Rng && rng, T init, Op op)
{
return (*this)(begin(rng), end(rng), std::move(init), std::move(op));
}
RANGES_FUNC_END(fold_right)
RANGES_FUNC_BEGIN(fold_right_last)
template(typename I, typename S, typename Op)(
requires sentinel_for<S, I> AND bidirectional_iterator<I> AND
indirectly_binary_right_foldable<Op, iter_value_t<I>, I>
AND constructible_from<iter_value_t<I>, iter_reference_t<I>>) //
constexpr auto
RANGES_FUNC(fold_right_last)(I first, S last, Op op)
{
using U = invoke_result_t<fold_right_fn, I, S, iter_value_t<I>, Op>;
if(first == last)
{
return optional<U>();
}
I tail = prev(next(first, std::move(last)));
return optional<U>(
in_place,
fold_right_fn{}(
std::move(first), tail, iter_value_t<I>(*tail), std::move(op)));
}
template(typename R, typename Op)(
requires bidirectional_range<R> AND
indirectly_binary_right_foldable<Op, range_value_t<R>, iterator_t<R>>
AND constructible_from<range_value_t<R>, range_reference_t<R>>) //
constexpr auto
RANGES_FUNC(fold_right_last)(R && rng, Op op)
{
return (*this)(begin(rng), end(rng), std::move(op));
}
RANGES_FUNC_END(fold_right_last)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,78 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FOR_EACH_HPP
#define RANGES_V3_ALGORITHM_FOR_EACH_HPP
#include <functional>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/functional/reference_wrapper.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename F>
using for_each_result = detail::in_fun_result<I, F>;
RANGES_FUNC_BEGIN(for_each)
/// \brief function template \c for_each
template(typename I, typename S, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirectly_unary_invocable<F, projected<I, P>>)
constexpr for_each_result<I, F> RANGES_FUNC(for_each)(I first, S last, F fun, P proj = P{})
{
for(; first != last; ++first)
{
invoke(fun, invoke(proj, *first));
}
return {detail::move(first), detail::move(fun)};
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirectly_unary_invocable<F, projected<iterator_t<Rng>, P>>)
constexpr for_each_result<borrowed_iterator_t<Rng>, F> //
RANGES_FUNC(for_each)(Rng && rng, F fun, P proj = P{})
{
return {(*this)(begin(rng), end(rng), ref(fun), detail::move(proj)).in,
detail::move(fun)};
}
RANGES_FUNC_END(for_each)
namespace cpp20
{
using ranges::for_each;
using ranges::for_each_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,77 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Rostislav Khlebnikov 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FOR_EACH_N_HPP
#define RANGES_V3_ALGORITHM_FOR_EACH_N_HPP
#include <functional>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(for_each_n)
/// \brief function template \c for_each_n
template(typename I, typename F, typename P = identity)(
requires input_iterator<I> AND
indirectly_unary_invocable<F, projected<I, P>>)
constexpr I RANGES_FUNC(for_each_n)(I first, iter_difference_t<I> n, F fun, P proj = P{})
{
RANGES_EXPECT(0 <= n);
auto norig = n;
auto b = uncounted(first);
for(; 0 < n; ++b, --n)
invoke(fun, invoke(proj, *b));
return recounted(first, b, norig);
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirectly_unary_invocable<F, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(for_each_n)(
Rng && rng, range_difference_t<Rng> n, F fun, P proj = P{})
{
if(sized_range<Rng>)
RANGES_EXPECT(n <= distance(rng));
return (*this)(begin(rng), n, detail::move(fun), detail::move(proj));
}
RANGES_FUNC_END(for_each_n)
namespace cpp20
{
using ranges::for_each_n;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,73 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_GENERATE_HPP
#define RANGES_V3_ALGORITHM_GENERATE_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/functional/reference_wrapper.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename O, typename F>
using generate_result = detail::out_fun_result<O, F>;
RANGES_FUNC_BEGIN(generate)
/// \brief function template \c generate_n
template(typename O, typename S, typename F)(
requires invocable<F &> AND output_iterator<O, invoke_result_t<F &>> AND
sentinel_for<S, O>)
constexpr generate_result<O, F> RANGES_FUNC(generate)(O first, S last, F fun) //
{
for(; first != last; ++first)
*first = invoke(fun);
return {detail::move(first), detail::move(fun)};
}
/// \overload
template(typename Rng, typename F)(
requires invocable<F &> AND output_range<Rng, invoke_result_t<F &>>)
constexpr generate_result<borrowed_iterator_t<Rng>, F> //
RANGES_FUNC(generate)(Rng && rng, F fun)
{
return {(*this)(begin(rng), end(rng), ref(fun)).out, detail::move(fun)};
}
RANGES_FUNC_END(generate)
namespace cpp20
{
using ranges::generate;
using ranges::generate_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,67 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_GENERATE_N_HPP
#define RANGES_V3_ALGORITHM_GENERATE_N_HPP
#include <tuple>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename O, typename F>
using generate_n_result = detail::out_fun_result<O, F>;
RANGES_FUNC_BEGIN(generate_n)
/// \brief function template \c generate_n
template(typename O, typename F)(
requires invocable<F &> AND output_iterator<O, invoke_result_t<F &>>)
constexpr generate_n_result<O, F> //
RANGES_FUNC(generate_n)(O first, iter_difference_t<O> n, F fun)
{
RANGES_EXPECT(n >= 0);
auto norig = n;
auto b = uncounted(first);
for(; 0 != n; ++b, --n)
*b = invoke(fun);
return {recounted(first, b, norig), detail::move(fun)};
}
RANGES_FUNC_END(generate_n)
namespace cpp20
{
using ranges::generate_n;
using ranges::generate_n_result;
} // namespace cpp20
// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,436 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_HEAP_ALGORITHM_HPP
#define RANGES_V3_ALGORITHM_HEAP_ALGORITHM_HPP
#include <functional>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
struct is_heap_until_n_fn
{
template(typename I, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr I operator()(I const begin_,
iter_difference_t<I> const n_,
C pred = C{},
P proj = P{}) const
{
RANGES_EXPECT(0 <= n_);
iter_difference_t<I> p = 0, c = 1;
I pp = begin_;
while(c < n_)
{
I cp = begin_ + c;
if(invoke(pred, invoke(proj, *pp), invoke(proj, *cp)))
return cp;
++c;
++cp;
if(c == n_ || invoke(pred, invoke(proj, *pp), invoke(proj, *cp)))
return cp;
++p;
++pp;
c = 2 * p + 1;
}
return begin_ + n_;
}
};
RANGES_INLINE_VARIABLE(is_heap_until_n_fn, is_heap_until_n)
struct is_heap_n_fn
{
template(typename I, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr bool operator()(I first,
iter_difference_t<I> n,
C pred = C{},
P proj = P{}) const
{
return is_heap_until_n(first, n, std::move(pred), std::move(proj)) ==
first + n;
}
};
RANGES_INLINE_VARIABLE(is_heap_n_fn, is_heap_n)
} // namespace detail
/// \endcond
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(is_heap_until)
/// \brief function template \c is_heap_until
template(typename I, typename S, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr I RANGES_FUNC(is_heap_until)(I first, S last, C pred = C{}, P proj = P{})
{
return detail::is_heap_until_n(std::move(first),
distance(first, last),
std::move(pred),
std::move(proj));
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires random_access_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(is_heap_until)(Rng && rng, C pred = C{}, P proj = P{})
{
return detail::is_heap_until_n(
begin(rng), distance(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(is_heap_until)
namespace cpp20
{
using ranges::is_heap_until;
}
RANGES_FUNC_BEGIN(is_heap)
/// \brief function template \c is_heap
template(typename I, typename S, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr bool RANGES_FUNC(is_heap)(I first, S last, C pred = C{}, P proj = P{}) //
{
return detail::is_heap_n(std::move(first),
distance(first, last),
std::move(pred),
std::move(proj));
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires random_access_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(is_heap)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return detail::is_heap_n(
begin(rng), distance(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(is_heap)
namespace cpp20
{
using ranges::is_heap;
}
/// @}
/// \cond
namespace detail
{
struct sift_up_n_fn
{
template<typename I, typename C = less, typename P = identity>
constexpr void operator()(I first,
iter_difference_t<I> len,
C pred = C{},
P proj = P{}) const
{
if(len > 1)
{
I last = first + len;
len = (len - 2) / 2;
I i = first + len;
if(invoke(pred, invoke(proj, *i), invoke(proj, *--last)))
{
iter_value_t<I> v = iter_move(last);
do
{
*last = iter_move(i);
last = i;
if(len == 0)
break;
len = (len - 1) / 2;
i = first + len;
} while(invoke(pred, invoke(proj, *i), invoke(proj, v)));
*last = std::move(v);
}
}
}
};
RANGES_INLINE_VARIABLE(sift_up_n_fn, sift_up_n)
struct sift_down_n_fn
{
template<typename I, typename C = less, typename P = identity>
constexpr void operator()(I first,
iter_difference_t<I> len,
I start,
C pred = C{},
P proj = P{}) const
{
// left-child of start is at 2 * start + 1
// right-child of start is at 2 * start + 2
auto child = start - first;
if(len < 2 || (len - 2) / 2 < child)
return;
child = 2 * child + 1;
I child_i = first + child;
if((child + 1) < len &&
invoke(pred, invoke(proj, *child_i), invoke(proj, *(child_i + 1))))
{
// right-child exists and is greater than left-child
++child_i;
++child;
}
// check if we are in heap-order
if(invoke(pred, invoke(proj, *child_i), invoke(proj, *start)))
// we are, start is larger than it's largest child
return;
iter_value_t<I> top = iter_move(start);
do
{
// we are not in heap-order, swap the parent with it's largest child
*start = iter_move(child_i);
start = child_i;
if((len - 2) / 2 < child)
break;
// recompute the child based off of the updated parent
child = 2 * child + 1;
child_i = first + child;
if((child + 1) < len &&
invoke(pred, invoke(proj, *child_i), invoke(proj, *(child_i + 1))))
{
// right-child exists and is greater than left-child
++child_i;
++child;
}
// check if we are in heap-order
} while(!invoke(pred, invoke(proj, *child_i), invoke(proj, top)));
*start = std::move(top);
}
};
RANGES_INLINE_VARIABLE(sift_down_n_fn, sift_down_n)
} // namespace detail
/// \endcond
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(push_heap)
/// \brief function template \c push_heap
template(typename I, typename S, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sentinel_for<S, I> AND
sortable<I, C, P>)
constexpr I RANGES_FUNC(push_heap)(I first, S last, C pred = C{}, P proj = P{})
{
auto n = distance(first, last);
detail::sift_up_n(first, n, std::move(pred), std::move(proj));
return first + n;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires random_access_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(push_heap)(Rng && rng, C pred = C{}, P proj = P{}) //
{
iterator_t<Rng> first = ranges::begin(rng);
auto n = distance(rng);
detail::sift_up_n(first, n, std::move(pred), std::move(proj));
return first + n;
}
RANGES_FUNC_END(push_heap)
namespace cpp20
{
using ranges::push_heap;
}
/// @}
/// \cond
namespace detail
{
struct pop_heap_n_fn
{
template(typename I, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sortable<I, C, P>)
constexpr void operator()(I first,
iter_difference_t<I> len,
C pred = C{},
P proj = P{}) const
{
if(len > 1)
{
ranges::iter_swap(first, first + (len - 1));
detail::sift_down_n(
first, len - 1, first, std::move(pred), std::move(proj));
}
}
};
RANGES_INLINE_VARIABLE(pop_heap_n_fn, pop_heap_n)
} // namespace detail
/// \endcond
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(pop_heap)
/// \brief function template \c pop_heap
template(typename I, typename S, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sentinel_for<S, I> AND
sortable<I, C, P>)
constexpr I RANGES_FUNC(pop_heap)(I first, S last, C pred = C{}, P proj = P{})
{
auto n = distance(first, last);
detail::pop_heap_n(first, n, std::move(pred), std::move(proj));
return first + n;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires random_access_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(pop_heap)(Rng && rng, C pred = C{}, P proj = P{})
{
iterator_t<Rng> first = ranges::begin(rng);
auto n = distance(rng);
detail::pop_heap_n(first, n, std::move(pred), std::move(proj));
return first + n;
}
RANGES_FUNC_END(pop_heap)
namespace cpp20
{
using ranges::pop_heap;
}
RANGES_FUNC_BEGIN(make_heap)
/// \brief function template \c make_heap
template(typename I, typename S, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sentinel_for<S, I> AND
sortable<I, C, P>)
constexpr I RANGES_FUNC(make_heap)(I first, S last, C pred = C{}, P proj = P{})
{
iter_difference_t<I> const n = distance(first, last);
if(n > 1)
// start from the first parent, there is no need to consider children
for(auto start = (n - 2) / 2; start >= 0; --start)
detail::sift_down_n(
first, n, first + start, ranges::ref(pred), ranges::ref(proj));
return first + n;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires random_access_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(make_heap)(Rng && rng, C pred = C{}, P proj = P{})
{
iterator_t<Rng> first = ranges::begin(rng);
auto const n = distance(rng);
if(n > 1)
// start from the first parent, there is no need to consider children
for(auto start = (n - 2) / 2; start >= 0; --start)
detail::sift_down_n(
first, n, first + start, ranges::ref(pred), ranges::ref(proj));
return first + n;
}
RANGES_FUNC_END(make_heap)
namespace cpp20
{
using ranges::make_heap;
}
RANGES_FUNC_BEGIN(sort_heap)
template(typename I, typename S, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sentinel_for<S, I> AND
sortable<I, C, P>)
constexpr I RANGES_FUNC(sort_heap)(I first, S last, C pred = C{}, P proj = P{})
{
iter_difference_t<I> const n = distance(first, last);
for(auto i = n; i > 1; --i)
detail::pop_heap_n(first, i, ranges::ref(pred), ranges::ref(proj));
return first + n;
}
template(typename Rng, typename C = less, typename P = identity)(
requires random_access_range<Rng &> AND sortable<iterator_t<Rng>, C, P>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(sort_heap)(Rng && rng, C pred = C{}, P proj = P{})
{
iterator_t<Rng> first = ranges::begin(rng);
auto const n = distance(rng);
for(auto i = n; i > 1; --i)
detail::pop_heap_n(first, i, ranges::ref(pred), ranges::ref(proj));
return first + n;
}
RANGES_FUNC_END(sort_heap)
namespace cpp20
{
using ranges::sort_heap;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,303 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_INPLACE_MERGE_HPP
#define RANGES_V3_ALGORITHM_INPLACE_MERGE_HPP
#include <functional>
#include <memory>
#include <new>
#include <type_traits>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/lower_bound.hpp>
#include <range/v3/algorithm/merge.hpp>
#include <range/v3/algorithm/min.hpp>
#include <range/v3/algorithm/move.hpp>
#include <range/v3/algorithm/rotate.hpp>
#include <range/v3/algorithm/upper_bound.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/functional/not_fn.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/move_iterators.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/reverse_iterator.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/memory.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
struct merge_adaptive_fn
{
private:
template<typename I, typename C, typename P>
static void impl(I first, I middle, I last, iter_difference_t<I> len1,
iter_difference_t<I> len2, iter_value_t<I> * const buf,
C & pred, P & proj)
{
auto tmpbuf = make_raw_buffer(buf);
if(len1 <= len2)
{
auto p = ranges::move(first, middle, tmpbuf.begin()).out;
merge(make_move_iterator(buf),
make_move_iterator(p.base().base()),
make_move_iterator(std::move(middle)),
make_move_iterator(std::move(last)),
std::move(first),
std::ref(pred),
std::ref(proj),
std::ref(proj));
}
else
{
auto p = ranges::move(middle, last, tmpbuf.begin()).out;
using RBi = ranges::reverse_iterator<I>;
using Rv = ranges::reverse_iterator<iter_value_t<I> *>;
merge(make_move_iterator(RBi{std::move(middle)}),
make_move_iterator(RBi{std::move(first)}),
make_move_iterator(Rv{p.base().base()}),
make_move_iterator(Rv{buf}),
RBi{std::move(last)},
not_fn(std::ref(pred)),
std::ref(proj),
std::ref(proj));
}
}
public:
template(typename I, typename C = less, typename P = identity)(
requires bidirectional_iterator<I> AND sortable<I, C, P>)
void operator()(I first, I middle, I last, iter_difference_t<I> len1,
iter_difference_t<I> len2, iter_value_t<I> * buf,
std::ptrdiff_t buf_size, C pred = C{}, P proj = P{}) const
{
using D = iter_difference_t<I>;
while(true)
{
// if middle == last, we're done
if(len2 == 0)
return;
// shrink [first, middle) as much as possible (with no moves),
// returning if it shrinks to 0
for(; true; ++first, --len1)
{
if(len1 == 0)
return;
if(invoke(pred, invoke(proj, *middle), invoke(proj, *first)))
break;
}
if(len1 <= buf_size || len2 <= buf_size)
{
merge_adaptive_fn::impl(std::move(first),
std::move(middle),
std::move(last),
len1,
len2,
buf,
pred,
proj);
return;
}
// first < middle < end
// *first > *middle
// partition [first, m1) [m1, middle) [middle, m2) [m2, last) such
// that
// all elements in:
// [first, m1) <= [middle, m2)
// [middle, m2) < [m1, middle)
// [m1, middle) <= [m2, last)
// and m1 or m2 is in the middle of its range
I m1; // "median" of [first, middle)
I m2; // "median" of [middle, last)
D len11; // distance(first, m1)
D len21; // distance(middle, m2)
// binary search smaller range
if(len1 < len2)
{ // len >= 1, len2 >= 2
len21 = len2 / 2;
m2 = next(middle, len21);
m1 = upper_bound(first,
middle,
invoke(proj, *m2),
std::ref(pred),
std::ref(proj));
len11 = distance(first, m1);
}
else
{
if(len1 == 1)
{ // len1 >= len2 && len2 > 0, therefore len2 == 1
// It is known *first > *middle
ranges::iter_swap(first, middle);
return;
}
// len1 >= 2, len2 >= 1
len11 = len1 / 2;
m1 = next(first, len11);
m2 = lower_bound(middle,
last,
invoke(proj, *m1),
std::ref(pred),
std::ref(proj));
len21 = distance(middle, m2);
}
D len12 = len1 - len11; // distance(m1, middle)
D len22 = len2 - len21; // distance(m2, last)
// [first, m1) [m1, middle) [middle, m2) [m2, last)
// swap middle two partitions
middle = rotate(m1, std::move(middle), m2).begin();
// len12 and len21 now have swapped meanings
// merge smaller range with recursive call and larger with tail
// recursion elimination
if(len11 + len21 < len12 + len22)
{
(*this)(std::move(first),
std::move(m1),
middle,
len11,
len21,
buf,
buf_size,
std::ref(pred),
std::ref(proj));
first = std::move(middle);
middle = std::move(m2);
len1 = len12;
len2 = len22;
}
else
{
(*this)(middle,
std::move(m2),
std::move(last),
len12,
len22,
buf,
buf_size,
std::ref(pred),
std::ref(proj));
last = std::move(middle);
middle = std::move(m1);
len1 = len11;
len2 = len21;
}
}
}
};
RANGES_INLINE_VARIABLE(merge_adaptive_fn, merge_adaptive)
struct inplace_merge_no_buffer_fn
{
template(typename I, typename C = less, typename P = identity)(
requires bidirectional_iterator<I> AND sortable<I, C, P>)
void operator()(I first, I middle, I last, iter_difference_t<I> len1,
iter_difference_t<I> len2, C pred = C{}, P proj = P{}) const
{
merge_adaptive(std::move(first),
std::move(middle),
std::move(last),
len1,
len2,
static_cast<iter_value_t<I> *>(nullptr),
0,
std::move(pred),
std::move(proj));
}
};
RANGES_INLINE_VARIABLE(inplace_merge_no_buffer_fn, inplace_merge_no_buffer)
} // namespace detail
/// \endcond
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(inplace_merge)
// TODO reimplement to only need forward iterators
/// \brief function template \c inplace_merge
template(typename I, typename S, typename C = less, typename P = identity)(
requires bidirectional_iterator<I> AND sortable<I, C, P>)
I RANGES_FUNC(inplace_merge)(
I first, I middle, S last, C pred = C{}, P proj = P{})
{
using value_type = iter_value_t<I>;
auto len1 = distance(first, middle);
auto len2_and_end = enumerate(middle, last);
auto buf_size = ranges::min(len1, len2_and_end.first);
std::pair<value_type *, std::ptrdiff_t> buf{nullptr, 0};
std::unique_ptr<value_type, detail::return_temporary_buffer> h;
if(detail::is_trivially_copy_assignable_v<value_type> && 8 < buf_size)
{
buf = detail::get_temporary_buffer<value_type>(buf_size);
h.reset(buf.first);
}
detail::merge_adaptive(std::move(first),
std::move(middle),
len2_and_end.second,
len1,
len2_and_end.first,
buf.first,
buf.second,
std::move(pred),
std::move(proj));
return len2_and_end.second;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires bidirectional_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
borrowed_iterator_t<Rng> RANGES_FUNC(inplace_merge)(
Rng && rng, iterator_t<Rng> middle, C pred = C{}, P proj = P{})
{
return (*this)(begin(rng),
std::move(middle),
end(rng),
std::move(pred),
std::move(proj));
}
RANGES_FUNC_END(inplace_merge)
namespace cpp20
{
using ranges::inplace_merge;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,80 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===-------------------------- algorithm ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_IS_PARTITIONED_HPP
#define RANGES_V3_ALGORITHM_IS_PARTITIONED_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(is_partitioned)
/// \brief function template \c is_partitioned
template(typename I, typename S, typename C, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr bool RANGES_FUNC(is_partitioned)(I first, S last, C pred, P proj = P{}) //
{
for(; first != last; ++first)
if(!invoke(pred, invoke(proj, *first)))
break;
for(; first != last; ++first)
if(invoke(pred, invoke(proj, *first)))
return false;
return true;
}
/// \overload
template(typename Rng, typename C, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(is_partitioned)(Rng && rng, C pred, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(is_partitioned)
namespace cpp20
{
using ranges::is_partitioned;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,77 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
#ifndef RANGES_V3_ALGORITHM_IS_SORTED_HPP
#define RANGES_V3_ALGORITHM_IS_SORTED_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/is_sorted_until.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(is_sorted)
/// \brief template function \c is_sorted
///
/// range-based version of the \c is_sorted std algorithm
///
/// Works on forward_ranges
///
/// \pre `Rng` is a model of the `forward_range` concept
/// \pre `I` is a model of the `forward_iterator` concept
/// \pre `S` and `I` model the `sentinel_for<S, I>` concept
/// \pre `R` and `projected<I, P>` model the `indirect_strict_weak_order<R,
/// projected<I, P>>` concept
///
template(typename I, typename S, typename R = less, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<R, projected<I, P>>)
constexpr bool RANGES_FUNC(is_sorted)(I first, S last, R rel = R{}, P proj = P{})
{
return is_sorted_until(
std::move(first), last, std::move(rel), std::move(proj)) == last;
}
/// \overload
template(typename Rng, typename R = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<R, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(is_sorted)(Rng && rng, R rel = R{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(rel), std::move(proj));
}
RANGES_FUNC_END(is_sorted)
namespace cpp20
{
using ranges::is_sorted;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,89 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
#ifndef RANGES_V3_ALGORITHM_IS_SORTED_UNTIL_HPP
#define RANGES_V3_ALGORITHM_IS_SORTED_UNTIL_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(is_sorted_until)
/// \brief template function \c is_sorted_until
///
/// range-based version of the \c is_sorted_until std algorithm
///
/// Works on forward_ranges
///
/// \pre `Rng` is a model of the `forward_range` concept
/// \pre `I` is a model of the `forward_iterator` concept
/// \pre `S` and `I` model the `sentinel_for<S, I>` concept
/// \pre `R` and `projected<I, P>` model the `indirect_strict_weak_order<R,
/// projected<I, P>>` concept
///
template(typename I, typename S, typename R = less, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<R, projected<I, P>>)
constexpr I RANGES_FUNC(is_sorted_until)(I first, S last, R pred = R{}, P proj = P{})
{
auto i = first;
if(first != last)
{
while(++i != last)
{
if(invoke(pred, invoke(proj, *i), invoke(proj, *first)))
return i;
first = i;
}
}
return i;
}
/// \overload
template(typename Rng, typename R = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<R, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(is_sorted_until)(Rng && rng, R pred = R{}, P proj = P{})
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(is_sorted_until)
namespace cpp20
{
using ranges::is_sorted_until;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,102 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
#define RANGES_V3_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(lexicographical_compare)
/// \brief function template \c lexicographical_compare
template(typename I0,
typename S0,
typename I1,
typename S1,
typename C = less,
typename P0 = identity,
typename P1 = identity)(
requires input_iterator<I0> AND sentinel_for<S0, I0> AND
input_iterator<I1> AND sentinel_for<S1, I1> AND
indirect_strict_weak_order<C, projected<I0, P0>, projected<I1, P1>>)
constexpr bool RANGES_FUNC(lexicographical_compare)(I0 begin0,
S0 end0,
I1 begin1,
S1 end1,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{})
{
for(; begin1 != end1; ++begin0, ++begin1)
{
if(begin0 == end0 ||
invoke(pred, invoke(proj0, *begin0), invoke(proj1, *begin1)))
return true;
if(invoke(pred, invoke(proj1, *begin1), invoke(proj0, *begin0)))
return false;
}
return false;
}
/// \overload
template(typename Rng0,
typename Rng1,
typename C = less,
typename P0 = identity,
typename P1 = identity)(
requires input_range<Rng0> AND input_range<Rng1> AND
indirect_strict_weak_order<C,
projected<iterator_t<Rng0>, P0>,
projected<iterator_t<Rng1>, P1>>)
constexpr bool RANGES_FUNC(lexicographical_compare)(Rng0 && rng0,
Rng1 && rng1,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{}) //
{
return (*this)(begin(rng0),
end(rng0),
begin(rng1),
end(rng1),
std::move(pred),
std::move(proj0),
std::move(proj1));
}
RANGES_FUNC_END(lexicographical_compare)
namespace cpp20
{
using ranges::lexicographical_compare;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,81 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_LOWER_BOUND_HPP
#define RANGES_V3_ALGORITHM_LOWER_BOUND_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/lower_bound_n.hpp>
#include <range/v3/algorithm/partition_point.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(lower_bound)
/// \brief function template \c lower_bound
template(typename I,
typename S,
typename V,
typename C = less,
typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, V const *, projected<I, P>>)
constexpr I RANGES_FUNC(lower_bound)(I first,
S last,
V const & val,
C pred = C{},
P proj = P{})
{
return partition_point(std::move(first),
std::move(last),
detail::make_lower_bound_predicate(pred, val),
std::move(proj));
}
/// \overload
template(typename Rng, typename V, typename C = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<C, V const *, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(lower_bound)(Rng && rng, V const & val, C pred = C{}, P proj = P{})
{
return partition_point(
rng, detail::make_lower_bound_predicate(pred, val), std::move(proj));
}
RANGES_FUNC_END(lower_bound)
namespace cpp20
{
using ranges::lower_bound;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,90 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MAX_HPP
#define RANGES_V3_ALGORITHM_MAX_HPP
#include <initializer_list>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(max)
/// \brief function template \c max
template(typename T, typename C = less, typename P = identity)(
requires indirect_strict_weak_order<C, projected<T const *, P>>)
constexpr T const & RANGES_FUNC(max)(
T const & a, T const & b, C pred = C{}, P proj = P{}) //
{
return invoke(pred, invoke(proj, b), invoke(proj, a)) ? a : b;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires input_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>> AND
indirectly_copyable_storable<iterator_t<Rng>, range_value_t<Rng> *>)
constexpr range_value_t<Rng> //
RANGES_FUNC(max)(Rng && rng, C pred = C{}, P proj = P{}) //
{
auto first = ranges::begin(rng);
auto last = ranges::end(rng);
RANGES_EXPECT(first != last);
range_value_t<Rng> result = *first;
while(++first != last)
{
auto && tmp = *first;
if(invoke(pred, invoke(proj, result), invoke(proj, tmp)))
result = (decltype(tmp) &&)tmp;
}
return result;
}
/// \overload
template(typename T, typename C = less, typename P = identity)(
requires copyable<T> AND
indirect_strict_weak_order<C, projected<T const *, P>>)
constexpr T RANGES_FUNC(max)(
std::initializer_list<T> const && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(rng, std::move(pred), std::move(proj));
}
RANGES_FUNC_END(max)
namespace cpp20
{
using ranges::max;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,72 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MAX_ELEMENT_HPP
#define RANGES_V3_ALGORITHM_MAX_ELEMENT_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(max_element)
/// \brief function template \c max_element
template(typename I, typename S, typename C = less, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr I RANGES_FUNC(max_element)(I first, S last, C pred = C{}, P proj = P{})
{
if(first != last)
for(auto tmp = next(first); tmp != last; ++tmp)
if(invoke(pred, invoke(proj, *first), invoke(proj, *tmp)))
first = tmp;
return first;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(max_element)(Rng && rng, C pred = C{}, P proj = P{})
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(max_element)
namespace cpp20
{
using ranges::max_element;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,136 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
//
// Algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef RANGES_V3_ALGORITHM_MERGE_HPP
#define RANGES_V3_ALGORITHM_MERGE_HPP
#include <tuple>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/copy.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I0, typename I1, typename O>
using merge_result = detail::in1_in2_out_result<I0, I1, O>;
RANGES_FUNC_BEGIN(merge)
/// \brief function template \c merge
template(typename I0,
typename S0,
typename I1,
typename S1,
typename O,
typename C = less,
typename P0 = identity,
typename P1 = identity)(
requires sentinel_for<S0, I0> AND sentinel_for<S1, I1> AND
mergeable<I0, I1, O, C, P0, P1>)
constexpr merge_result<I0, I1, O> RANGES_FUNC(merge)(I0 begin0,
S0 end0,
I1 begin1,
S1 end1,
O out,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{}) //
{
for(; begin0 != end0 && begin1 != end1; ++out)
{
if(invoke(pred, invoke(proj1, *begin1), invoke(proj0, *begin0)))
{
*out = *begin1;
++begin1;
}
else
{
*out = *begin0;
++begin0;
}
}
auto t0 = ranges::copy(begin0, end0, out);
auto t1 = ranges::copy(begin1, end1, t0.out);
return {t0.in, t1.in, t1.out};
}
/// \overload
template(typename Rng0,
typename Rng1,
typename O,
typename C = less,
typename P0 = identity,
typename P1 = identity)(
requires range<Rng0> AND range<Rng1> AND
mergeable<iterator_t<Rng0>, iterator_t<Rng1>, O, C, P0, P1>)
constexpr merge_result<borrowed_iterator_t<Rng0>, borrowed_iterator_t<Rng1>, O>
RANGES_FUNC(merge)(Rng0 && rng0,
Rng1 && rng1,
O out,
C pred = C{},
P0 proj0 = P0{},
P1 proj1 = P1{})
{
return (*this)(begin(rng0),
end(rng0),
begin(rng1),
end(rng1),
std::move(out),
std::move(pred),
std::move(proj0),
std::move(proj1));
}
RANGES_FUNC_END(merge)
namespace cpp20
{
using ranges::merge;
using ranges::merge_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,90 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MIN_HPP
#define RANGES_V3_ALGORITHM_MIN_HPP
#include <initializer_list>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(min)
/// \brief function template \c min
template(typename T, typename C = less, typename P = identity)(
requires indirect_strict_weak_order<C, projected<T const *, P>>)
constexpr T const & RANGES_FUNC(min)(
T const & a, T const & b, C pred = C{}, P proj = P{}) //
{
return invoke(pred, invoke(proj, b), invoke(proj, a)) ? b : a;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires input_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>> AND
indirectly_copyable_storable<iterator_t<Rng>, range_value_t<Rng> *>)
constexpr range_value_t<Rng> //
RANGES_FUNC(min)(Rng && rng, C pred = C{}, P proj = P{}) //
{
auto first = ranges::begin(rng);
auto last = ranges::end(rng);
RANGES_EXPECT(first != last);
range_value_t<Rng> result = *first;
while(++first != last)
{
auto && tmp = *first;
if(invoke(pred, invoke(proj, tmp), invoke(proj, result)))
result = (decltype(tmp) &&)tmp;
}
return result;
}
/// \overload
template(typename T, typename C = less, typename P = identity)(
requires copyable<T> AND
indirect_strict_weak_order<C, projected<T const *, P>>)
constexpr T RANGES_FUNC(min)(
std::initializer_list<T> const && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(rng, std::move(pred), std::move(proj));
}
RANGES_FUNC_END(min)
namespace cpp20
{
using ranges::min;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,72 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MIN_ELEMENT_HPP
#define RANGES_V3_ALGORITHM_MIN_ELEMENT_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(min_element)
/// \brief function template \c min_element
template(typename I, typename S, typename C = less, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr I RANGES_FUNC(min_element)(I first, S last, C pred = C{}, P proj = P{})
{
if(first != last)
for(auto tmp = next(first); tmp != last; ++tmp)
if(invoke(pred, invoke(proj, *tmp), invoke(proj, *first)))
first = tmp;
return first;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(min_element)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(min_element)
namespace cpp20
{
using ranges::min_element;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,130 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MINMAX_HPP
#define RANGES_V3_ALGORITHM_MINMAX_HPP
#include <initializer_list>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename T>
using minmax_result = detail::min_max_result<T, T>;
RANGES_FUNC_BEGIN(minmax)
/// \brief function template \c minmax
template(typename T, typename C = less, typename P = identity)(
requires indirect_strict_weak_order<C, projected<T const *, P>>)
constexpr minmax_result<T const &> RANGES_FUNC(minmax)(
T const & a, T const & b, C pred = C{}, P proj = P{}) //
{
using R = minmax_result<T const &>;
return invoke(pred, invoke(proj, b), invoke(proj, a)) ? R{b, a} : R{a, b};
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires input_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>> AND
indirectly_copyable_storable<iterator_t<Rng>, range_value_t<Rng> *>)
constexpr minmax_result<range_value_t<Rng>> //
RANGES_FUNC(minmax)(Rng && rng, C pred = C{}, P proj = P{}) //
{
using R = minmax_result<range_value_t<Rng>>;
auto first = ranges::begin(rng);
auto last = ranges::end(rng);
RANGES_EXPECT(first != last);
auto result = R{*first, *first};
if(++first != last)
{
{
auto && tmp = *first;
if(invoke(pred, invoke(proj, tmp), invoke(proj, result.min)))
result.min = (decltype(tmp) &&)tmp;
else
result.max = (decltype(tmp) &&)tmp;
}
while(++first != last)
{
range_value_t<Rng> tmp1 = *first;
if(++first == last)
{
if(invoke(pred, invoke(proj, tmp1), invoke(proj, result.min)))
result.min = std::move(tmp1);
else if(!invoke(
pred, invoke(proj, tmp1), invoke(proj, result.max)))
result.max = std::move(tmp1);
break;
}
auto && tmp2 = *first;
if(invoke(pred, invoke(proj, tmp2), invoke(proj, tmp1)))
{
if(invoke(pred, invoke(proj, tmp2), invoke(proj, result.min)))
result.min = (decltype(tmp2) &&)tmp2;
if(!invoke(pred, invoke(proj, tmp1), invoke(proj, result.max)))
result.max = std::move(tmp1);
}
else
{
if(invoke(pred, invoke(proj, tmp1), invoke(proj, result.min)))
result.min = std::move(tmp1);
if(!invoke(pred, invoke(proj, tmp2), invoke(proj, result.max)))
result.max = (decltype(tmp2) &&)tmp2;
}
}
}
return result;
}
/// \overload
template(typename T, typename C = less, typename P = identity)(
requires copyable<T> AND
indirect_strict_weak_order<C, projected<T const *, P>>)
constexpr minmax_result<T> RANGES_FUNC(minmax)(
std::initializer_list<T> const && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(rng, std::move(pred), std::move(proj));
}
RANGES_FUNC_END(minmax)
namespace cpp20
{
using ranges::minmax;
using ranges::minmax_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,112 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
#ifndef RANGES_V3_ALGORITHM_MINMAX_ELEMENT_HPP
#define RANGES_V3_ALGORITHM_MINMAX_ELEMENT_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I>
using minmax_element_result = detail::min_max_result<I, I>;
RANGES_FUNC_BEGIN(minmax_element)
/// \brief function template \c minmax_element
template(typename I, typename S, typename C = less, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr minmax_element_result<I> //
RANGES_FUNC(minmax_element)(I first, S last, C pred = C{}, P proj = P{}) //
{
minmax_element_result<I> result{first, first};
if(first == last || ++first == last)
return result;
if(invoke(pred, invoke(proj, *first), invoke(proj, *result.min)))
result.min = first;
else
result.max = first;
while(++first != last)
{
I tmp = first;
if(++first == last)
{
if(invoke(pred, invoke(proj, *tmp), invoke(proj, *result.min)))
result.min = tmp;
else if(!invoke(pred, invoke(proj, *tmp), invoke(proj, *result.max)))
result.max = tmp;
break;
}
else
{
if(invoke(pred, invoke(proj, *first), invoke(proj, *tmp)))
{
if(invoke(pred, invoke(proj, *first), invoke(proj, *result.min)))
result.min = first;
if(!invoke(pred, invoke(proj, *tmp), invoke(proj, *result.max)))
result.max = tmp;
}
else
{
if(invoke(pred, invoke(proj, *tmp), invoke(proj, *result.min)))
result.min = tmp;
if(!invoke(pred, invoke(proj, *first), invoke(proj, *result.max)))
result.max = first;
}
}
}
return result;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
constexpr minmax_element_result<borrowed_iterator_t<Rng>> //
RANGES_FUNC(minmax_element)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(minmax_element)
namespace cpp20
{
using ranges::minmax_element;
using ranges::minmax_element_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,175 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MISMATCH_HPP
#define RANGES_V3_ALGORITHM_MISMATCH_HPP
#include <utility>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I1, typename I2>
using mismatch_result = detail::in1_in2_result<I1, I2>;
RANGES_FUNC_BEGIN(mismatch)
/// \brief function template \c mismatch
template(typename I1,
typename S1,
typename I2,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)(
requires input_iterator<I1> AND sentinel_for<S1, I1> AND
input_iterator<I2> AND
indirect_relation<C, projected<I1, P1>, projected<I2, P2>>)
RANGES_DEPRECATED(
"Use the variant of ranges::mismatch that takes an upper bound for "
"both sequences")
mismatch_result<I1, I2> RANGES_FUNC(mismatch)(I1 begin1,
S1 end1,
I2 begin2,
C pred = C{},
P1 proj1 = P1{},
P2 proj2 = P2{}) //
{
for(; begin1 != end1; ++begin1, ++begin2)
if(!invoke(pred, invoke(proj1, *begin1), invoke(proj2, *begin2)))
break;
return {begin1, begin2};
}
/// \overload
template(typename I1,
typename S1,
typename I2,
typename S2,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)(
requires input_iterator<I1> AND sentinel_for<S1, I1> AND
input_iterator<I2> AND sentinel_for<S2, I2> AND
indirect_relation<C, projected<I1, P1>, projected<I2, P2>>)
constexpr mismatch_result<I1, I2> RANGES_FUNC(mismatch)(I1 begin1,
S1 end1,
I2 begin2,
S2 end2,
C pred = C{},
P1 proj1 = P1{},
P2 proj2 = P2{}) //
{
for(; begin1 != end1 && begin2 != end2; ++begin1, ++begin2)
if(!invoke(pred, invoke(proj1, *begin1), invoke(proj2, *begin2)))
break;
return {begin1, begin2};
}
/// \overload
template(typename Rng1,
typename I2Ref,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)( //s
requires input_range<Rng1> AND input_iterator<uncvref_t<I2Ref>> AND
indirect_relation<C,
projected<iterator_t<Rng1>, P1>,
projected<uncvref_t<I2Ref>, P2>>)
RANGES_DEPRECATED(
"Use the variant of ranges::mismatch that takes an upper bound for "
"both sequences")
mismatch_result<borrowed_iterator_t<Rng1>, uncvref_t<I2Ref>>
RANGES_FUNC(mismatch)(Rng1 && rng1,
I2Ref && begin2,
C pred = C{}, // see below [*]
P1 proj1 = P1{},
P2 proj2 = P2{}) //
{
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
return (*this)(begin(rng1),
end(rng1),
static_cast<uncvref_t<I2Ref> &&>(begin2),
std::move(pred),
std::move(proj1),
std::move(proj2));
RANGES_DIAGNOSTIC_POP
}
/// \overload
template(typename Rng1,
typename Rng2,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)(
requires input_range<Rng1> AND input_range<Rng2> AND
indirect_relation<C,
projected<iterator_t<Rng1>, P1>,
projected<iterator_t<Rng2>, P2>>)
constexpr mismatch_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>> //
RANGES_FUNC(mismatch)(Rng1 && rng1,
Rng2 && rng2,
C pred = C{},
P1 proj1 = P1{},
P2 proj2 = P2{}) //
{
return (*this)(begin(rng1),
end(rng1),
begin(rng2),
end(rng2),
std::move(pred),
std::move(proj1),
std::move(proj2));
}
RANGES_FUNC_END(mismatch)
namespace cpp20
{
using ranges::mismatch;
using ranges::mismatch_result;
} // namespace cpp20
// [*] In this case, the 'begin2' iterator is taken by universal reference. Why? So
// that we can properly distinguish this case:
// int x[] = {1,2,3,4};
// int y[] = {1,2,3,4};
// mismatch(x, y);
// Had 'begin2' been taken by value as is customary, this call could match as either
// two ranges, or a range and an iterator, where the iterator is the array, decayed
// to a pointer. Yuk!
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,88 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MOVE_HPP
#define RANGES_V3_ALGORITHM_MOVE_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/move.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using move_result = detail::in_out_result<I, O>;
RANGES_HIDDEN_DETAIL(namespace _move CPP_PP_LBRACE())
RANGES_FUNC_BEGIN(move)
/// \brief function template \c move
template(typename I, typename S, typename O)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O> AND indirectly_movable<I, O>)
constexpr move_result<I, O> RANGES_FUNC(move)(I first, S last, O out) //
{
for(; first != last; ++first, ++out)
*out = iter_move(first);
return {first, out};
}
/// \overload
template(typename Rng, typename O)(
requires input_range<Rng> AND weakly_incrementable<O> AND
indirectly_movable<iterator_t<Rng>, O>)
constexpr move_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(move)(Rng && rng, O out) //
{
return (*this)(begin(rng), end(rng), std::move(out));
}
RANGES_FUNC_END(move)
RANGES_HIDDEN_DETAIL(CPP_PP_RBRACE())
#ifndef RANGES_DOXYGEN_INVOKED
struct RANGES_EMPTY_BASES move_fn
: aux::move_fn
, _move::move_fn
{
using aux::move_fn::operator();
using _move::move_fn::operator();
};
RANGES_INLINE_VARIABLE(move_fn, move)
#endif
namespace cpp20
{
using ranges::move_result;
using ranges::RANGES_HIDDEN_DETAIL(_move::) move;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,75 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MOVE_BACKWARD_HPP
#define RANGES_V3_ALGORITHM_MOVE_BACKWARD_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using move_backward_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(move_backward)
/// \brief function template \c move_backward
template(typename I, typename S, typename O)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
bidirectional_iterator<O> AND indirectly_movable<I, O>)
constexpr move_backward_result<I, O> RANGES_FUNC(move_backward)(I first, S end_, O out) //
{
I i = ranges::next(first, end_), last = i;
while(first != i)
*--out = iter_move(--i);
return {last, out};
}
/// \overload
template(typename Rng, typename O)(
requires bidirectional_range<Rng> AND bidirectional_iterator<O> AND
indirectly_movable<iterator_t<Rng>, O>)
constexpr move_backward_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(move_backward)(Rng && rng, O out) //
{
return (*this)(begin(rng), end(rng), std::move(out));
}
RANGES_FUNC_END(move_backward)
namespace cpp20
{
using ranges::move_backward;
using ranges::move_backward_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,70 @@
/// \file
// Range v3 library
//
// Copyright Andrew Sutton 2014
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_NONE_OF_HPP
#define RANGES_V3_ALGORITHM_NONE_OF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(none_of)
/// \brief function template \c none_of
template(typename I, typename S, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<F, projected<I, P>>)
constexpr bool RANGES_FUNC(none_of)(I first, S last, F pred, P proj = P{}) //
{
for(; first != last; ++first)
if(invoke(pred, invoke(proj, *first)))
return false;
return true;
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(none_of)(Rng && rng, F pred, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(none_of)
namespace cpp20
{
using ranges::none_of;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,337 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_NTH_ELEMENT_HPP
#define RANGES_V3_ALGORITHM_NTH_ELEMENT_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/min_element.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/optional.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
// stable, 2-3 compares, 0-2 swaps
template(typename I, typename C, typename P)(
requires forward_iterator<I> AND indirect_relation<C, projected<I, P>>)
unsigned sort3(I x, I y, I z, C & pred, P & proj)
{
unsigned r = 0;
if(!invoke(pred, invoke(proj, *y), invoke(proj, *x))) // if x <= y
{
if(!invoke(pred, invoke(proj, *z), invoke(proj, *y))) // if y <= z
return r; // x <= y && y <= z
// x <= y && y > z
ranges::iter_swap(y, z); // x <= z && y < z
r = 1;
if(invoke(pred, invoke(proj, *y), invoke(proj, *x))) // if x > y
{
ranges::iter_swap(x, y); // x < y && y <= z
r = 2;
}
return r; // x <= y && y < z
}
if(invoke(pred, invoke(proj, *z), invoke(proj, *y))) // x > y, if y > z
{
ranges::iter_swap(x, z); // x < y && y < z
r = 1;
return r;
}
ranges::iter_swap(x, y); // x > y && y <= z
r = 1; // x < y && x <= z
if(invoke(pred, invoke(proj, *z), invoke(proj, *y))) // if y > z
{
ranges::iter_swap(y, z); // x <= y && y < z
r = 2;
}
return r;
} // x <= y && y <= z
template(typename I, typename C, typename P)(
requires bidirectional_iterator<I> AND indirect_relation<C, projected<I, P>>)
void selection_sort(I first, I last, C & pred, P & proj)
{
RANGES_EXPECT(first != last);
for(I lm1 = ranges::prev(last); first != lm1; ++first)
{
I i = ranges::min_element(first, last, std::ref(pred), std::ref(proj));
if(i != first)
ranges::iter_swap(first, i);
}
}
} // namespace detail
/// \endcond
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(nth_element)
/// \brief function template \c nth_element
template(typename I, typename S, typename C = less, typename P = identity)(
requires random_access_iterator<I> AND sortable<I, C, P>)
constexpr I RANGES_FUNC(nth_element)(
I first, I nth, S end_, C pred = C{}, P proj = P{}) //
{
I last = ranges::next(nth, end_), end_orig = last;
// C is known to be a reference type
using difference_type = iter_difference_t<I>;
difference_type const limit = 7;
while(true)
{
if(nth == last)
return end_orig;
difference_type len = last - first;
switch(len)
{
case 0:
case 1:
return end_orig;
case 2:
if(invoke(pred, invoke(proj, *--last), invoke(proj, *first)))
ranges::iter_swap(first, last);
return end_orig;
case 3:
{
I m = first;
detail::sort3(first, ++m, --last, pred, proj);
return end_orig;
}
}
if(len <= limit)
{
detail::selection_sort(first, last, pred, proj);
return end_orig;
}
// len > limit >= 3
I m = first + len / 2;
I lm1 = last;
unsigned n_swaps = detail::sort3(first, m, --lm1, pred, proj);
// *m is median
// partition [first, m) < *m and *m <= [m, last)
//(this inhibits tossing elements equivalent to m around unnecessarily)
I i = first;
I j = lm1;
// j points beyond range to be tested, *lm1 is known to be <= *m
// The search going up is known to be guarded but the search coming down
// isn't. Prime the downward search with a guard.
if(!invoke(pred, invoke(proj, *i), invoke(proj, *m))) // if *first == *m
{
// *first == *m, *first doesn't go in first part
// manually guard downward moving j against i
while(true)
{
if(i == --j)
{
// *first == *m, *m <= all other elements
// Parition instead into [first, i) == *first and *first < [i,
// last)
++i; // first + 1
j = last;
if(!invoke(
pred,
invoke(proj, *first),
invoke(
proj,
*--j))) // we need a guard if *first == *(last-1)
{
while(true)
{
if(i == j)
return end_orig; // [first, last) all equivalent
// elements
if(invoke(
pred, invoke(proj, *first), invoke(proj, *i)))
{
ranges::iter_swap(i, j);
++n_swaps;
++i;
break;
}
++i;
}
}
// [first, i) == *first and *first < [j, last) and j == last -
// 1
if(i == j)
return end_orig;
while(true)
{
while(
!invoke(pred, invoke(proj, *first), invoke(proj, *i)))
++i;
while(invoke(
pred, invoke(proj, *first), invoke(proj, *--j)))
;
if(i >= j)
break;
ranges::iter_swap(i, j);
++n_swaps;
++i;
}
// [first, i) == *first and *first < [i, last)
// The first part is sorted,
if(nth < i)
return end_orig;
// nth_element the second part
// nth_element<C>(i, nth, last, pred);
first = i;
continue;
}
if(invoke(pred, invoke(proj, *j), invoke(proj, *m)))
{
ranges::iter_swap(i, j);
++n_swaps;
break; // found guard for downward moving j, now use unguarded
// partition
}
}
}
++i;
// j points beyond range to be tested, *lm1 is known to be <= *m
// if not yet partitioned...
if(i < j)
{
// known that *(i - 1) < *m
while(true)
{
// m still guards upward moving i
while(invoke(pred, invoke(proj, *i), invoke(proj, *m)))
++i;
// It is now known that a guard exists for downward moving j
while(!invoke(pred, invoke(proj, *--j), invoke(proj, *m)))
;
if(i >= j)
break;
ranges::iter_swap(i, j);
++n_swaps;
// It is known that m != j
// If m just moved, follow it
if(m == i)
m = j;
++i;
}
}
// [first, i) < *m and *m <= [i, last)
if(i != m && invoke(pred, invoke(proj, *m), invoke(proj, *i)))
{
ranges::iter_swap(i, m);
++n_swaps;
}
// [first, i) < *i and *i <= [i+1, last)
if(nth == i)
return end_orig;
const auto optional_return = [&]() -> ranges::optional<I> {
if(n_swaps == 0)
{
// We were given a perfectly partitioned sequence. Coincidence?
if(nth < i)
{
// Check for [first, i) already sorted
j = m = first;
while(++j != i)
{
if(invoke(pred, invoke(proj, *j), invoke(proj, *m)))
// not yet sorted, so sort
return ranges::nullopt;
m = j;
}
// [first, i) sorted
return end_orig;
}
else
{
// Check for [i, last) already sorted
j = m = i;
while(++j != last)
{
if(invoke(pred, invoke(proj, *j), invoke(proj, *m)))
// not yet sorted, so sort
return ranges::nullopt;
m = j;
}
// [i, last) sorted
return end_orig;
}
}
return ranges::nullopt;
}();
if(optional_return)
{
return *optional_return;
}
// nth_element on range containing nth
if(nth < i)
{
// nth_element<C>(first, nth, i, pred);
last = i;
}
else
{
// nth_element<C>(i+1, nth, last, pred);
first = ++i;
}
}
return end_orig;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires random_access_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(nth_element)(
Rng && rng, iterator_t<Rng> nth, C pred = C{}, P proj = P{}) //
{
return (*this)(
begin(rng), std::move(nth), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(nth_element)
namespace cpp20
{
using ranges::nth_element;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,87 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_PARTIAL_SORT_HPP
#define RANGES_V3_ALGORITHM_PARTIAL_SORT_HPP
#include <functional>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/heap_algorithm.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(partial_sort)
/// \brief function template \c partial_sort
template(typename I, typename S, typename C = less, typename P = identity)(
requires sortable<I, C, P> AND random_access_iterator<I> AND
sentinel_for<S, I>)
constexpr I RANGES_FUNC(partial_sort)(
I first, I middle, S last, C pred = C{}, P proj = P{}) //
{
make_heap(first, middle, ranges::ref(pred), ranges::ref(proj));
auto const len = middle - first;
I i = middle;
for(; i != last; ++i)
{
if(invoke(pred, invoke(proj, *i), invoke(proj, *first)))
{
iter_swap(i, first);
detail::sift_down_n(
first, len, first, ranges::ref(pred), ranges::ref(proj));
}
}
sort_heap(first, middle, ranges::ref(pred), ranges::ref(proj));
return i;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires sortable<iterator_t<Rng>, C, P> AND random_access_range<Rng>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(partial_sort)(
Rng && rng, iterator_t<Rng> middle, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng),
std::move(middle),
end(rng),
std::move(pred),
std::move(proj));
}
RANGES_FUNC_END(partial_sort)
namespace cpp20
{
using ranges::partial_sort;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,123 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_PARTIAL_SORT_COPY_HPP
#define RANGES_V3_ALGORITHM_PARTIAL_SORT_COPY_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/heap_algorithm.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(partial_sort_copy)
/// \brief function template \c partial_sort_copy
template(typename I,
typename SI,
typename O,
typename SO,
typename C = less,
typename PI = identity,
typename PO = identity)(
requires input_iterator<I> AND sentinel_for<SI, I> AND
random_access_iterator<O> AND sentinel_for<SO, O> AND
indirectly_copyable<I, O> AND sortable<O, C, PO> AND
indirect_strict_weak_order<C, projected<I, PI>, projected<O, PO>>)
constexpr O RANGES_FUNC(partial_sort_copy)(I first,
SI last,
O out_begin,
SO out_end,
C pred = C{},
PI in_proj = PI{},
PO out_proj = PO{}) //
{
O r = out_begin;
if(r != out_end)
{
for(; first != last && r != out_end; ++first, ++r)
*r = *first;
make_heap(out_begin, r, ranges::ref(pred), ranges::ref(out_proj));
auto len = r - out_begin;
for(; first != last; ++first)
{
auto && x = *first;
if(invoke(pred, invoke(in_proj, x), invoke(out_proj, *out_begin)))
{
*out_begin = (decltype(x) &&)x;
detail::sift_down_n(out_begin,
len,
out_begin,
ranges::ref(pred),
ranges::ref(out_proj));
}
}
sort_heap(out_begin, r, ranges::ref(pred), ranges::ref(out_proj));
}
return r;
}
/// \overload
template(typename InRng,
typename OutRng,
typename C = less,
typename PI = identity,
typename PO = identity)(
requires input_range<InRng> AND random_access_range<OutRng> AND
indirectly_copyable<iterator_t<InRng>, iterator_t<OutRng>> AND
sortable<iterator_t<OutRng>, C, PO> AND
indirect_strict_weak_order<C,
projected<iterator_t<InRng>, PI>,
projected<iterator_t<OutRng>, PO>>)
constexpr borrowed_iterator_t<OutRng> RANGES_FUNC(partial_sort_copy)(InRng && in_rng,
OutRng && out_rng,
C pred = C{},
PI in_proj = PI{},
PO out_proj = PO{}) //
{
return (*this)(begin(in_rng),
end(in_rng),
begin(out_rng),
end(out_rng),
std::move(pred),
std::move(in_proj),
std::move(out_proj));
}
RANGES_FUNC_END(partial_sort_copy)
namespace cpp20
{
using ranges::partial_sort_copy;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,137 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===-------------------------- algorithm ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_PARTITION_HPP
#define RANGES_V3_ALGORITHM_PARTITION_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// \cond
namespace detail
{
template<typename I, typename S, typename C, typename P>
constexpr I partition_impl(I first, S last, C pred, P proj, std::forward_iterator_tag)
{
while(true)
{
if(first == last)
return first;
if(!invoke(pred, invoke(proj, *first)))
break;
++first;
}
for(I p = first; ++p != last;)
{
if(invoke(pred, invoke(proj, *p)))
{
ranges::iter_swap(first, p);
++first;
}
}
return first;
}
template<typename I, typename S, typename C, typename P>
constexpr I partition_impl(I first, S end_, C pred, P proj, std::bidirectional_iterator_tag)
{
I last = ranges::next(first, end_);
while(true)
{
while(true)
{
if(first == last)
return first;
if(!invoke(pred, invoke(proj, *first)))
break;
++first;
}
do
{
if(first == --last)
return first;
} while(!invoke(pred, invoke(proj, *last)));
ranges::iter_swap(first, last);
++first;
}
}
} // namespace detail
/// \endcond
RANGES_FUNC_BEGIN(partition)
/// \brief function template \c partition
template(typename I, typename S, typename C, typename P = identity)(
requires permutable<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr I RANGES_FUNC(partition)(I first, S last, C pred, P proj = P{})
{
return detail::partition_impl(std::move(first),
std::move(last),
std::move(pred),
std::move(proj),
iterator_tag_of<I>());
}
/// \overload
template(typename Rng, typename C, typename P = identity)(
requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(partition)(Rng && rng, C pred, P proj = P{})
{
return detail::partition_impl(begin(rng),
end(rng),
std::move(pred),
std::move(proj),
iterator_tag_of<iterator_t<Rng>>());
}
RANGES_FUNC_END(partition)
namespace cpp20
{
using ranges::partition;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,109 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
#define RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
#include <tuple>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O0, typename O1>
using partition_copy_result = detail::in_out1_out2_result<I, O0, O1>;
RANGES_FUNC_BEGIN(partition_copy)
/// \brief function template \c partition_copy
template(typename I,
typename S,
typename O0,
typename O1,
typename C,
typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O0> AND weakly_incrementable<O1> AND
indirectly_copyable<I, O0> AND indirectly_copyable<I, O1> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr partition_copy_result<I, O0, O1> RANGES_FUNC(partition_copy)(
I first, S last, O0 o0, O1 o1, C pred, P proj = P{})
{
for(; first != last; ++first)
{
auto && x = *first;
if(invoke(pred, invoke(proj, x)))
{
*o0 = (decltype(x) &&)x;
++o0;
}
else
{
*o1 = (decltype(x) &&)x;
++o1;
}
}
return {first, o0, o1};
}
/// \overload
template(typename Rng,
typename O0,
typename O1,
typename C,
typename P = identity)(
requires input_range<Rng> AND weakly_incrementable<O0> AND
weakly_incrementable<O1> AND indirectly_copyable<iterator_t<Rng>, O0> AND
indirectly_copyable<iterator_t<Rng>, O1> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
constexpr partition_copy_result<borrowed_iterator_t<Rng>, O0, O1> //
RANGES_FUNC(partition_copy)(Rng && rng, O0 o0, O1 o1, C pred, P proj = P{})
{
return (*this)(begin(rng),
end(rng),
std::move(o0),
std::move(o1),
std::move(pred),
std::move(proj));
}
RANGES_FUNC_END(partition_copy)
namespace cpp20
{
using ranges::partition_copy;
using ranges::partition_copy_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,108 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===-------------------------- algorithm ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_PARTITION_POINT_HPP
#define RANGES_V3_ALGORITHM_PARTITION_POINT_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/partition_point_n.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(partition_point)
/// \brief function template \c partition_point
template(typename I, typename S, typename C, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr I RANGES_FUNC(partition_point)(I first, S last, C pred, P proj = P{})
{
if(RANGES_CONSTEXPR_IF(sized_sentinel_for<S, I>))
{
auto len = distance(first, std::move(last));
return aux::partition_point_n(
std::move(first), len, std::move(pred), std::move(proj));
}
// Probe exponentially for either last-of-range or an iterator
// that is past the partition point (i.e., does not satisfy pred).
auto len = iter_difference_t<I>{1};
while(true)
{
auto mid = first;
auto d = advance(mid, len, last);
if(mid == last || !invoke(pred, invoke(proj, *mid)))
{
len -= d;
return aux::partition_point_n(
std::move(first), len, ranges::ref(pred), ranges::ref(proj));
}
first = std::move(mid);
len *= 2;
}
}
/// \overload
template(typename Rng, typename C, typename P = identity)(
requires forward_range<Rng> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(partition_point)(Rng && rng, C pred, P proj = P{}) //
{
if(RANGES_CONSTEXPR_IF(sized_range<Rng>))
{
auto len = distance(rng);
return aux::partition_point_n(
begin(rng), len, std::move(pred), std::move(proj));
}
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(partition_point)
namespace cpp20
{
using ranges::partition_point;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,374 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===-------------------------- algorithm ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_PERMUTATION_HPP
#define RANGES_V3_ALGORITHM_PERMUTATION_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/mismatch.hpp>
#include <range/v3/algorithm/reverse.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// \cond
namespace detail
{
template<typename I1, typename S1, typename I2, typename S2, typename C,
typename P1, typename P2>
constexpr bool is_permutation_impl(I1 begin1,
S1 end1,
I2 begin2,
S2 end2,
C pred,
P1 proj1,
P2 proj2)
{
// shorten sequences as much as possible by lopping off any equal parts
const auto mismatch =
ranges::mismatch(begin1, end1, begin2, end2, pred, proj1, proj2);
begin1 = mismatch.in1;
begin2 = mismatch.in2;
if(begin1 == end1 || begin2 == end2)
{
return begin1 == end1 && begin2 == end2;
}
// begin1 != end1 && begin2 != end2 && *begin1 != *begin2
auto l1 = distance(begin1, end1);
auto l2 = distance(begin2, end2);
if(l1 != l2)
return false;
// For each element in [f1, l1) see if there are the same number of
// equal elements in [f2, l2)
for(I1 i = begin1; i != end1; ++i)
{
// Have we already counted the number of *i in [f1, l1)?
const auto should_continue = [&] {
for(I1 j = begin1; j != i; ++j)
if(invoke(pred, invoke(proj1, *j), invoke(proj1, *i)))
return true;
return false;
}();
if(should_continue)
{
continue;
}
// Count number of *i in [f2, l2)
iter_difference_t<I2> c2 = 0;
for(I2 j = begin2; j != end2; ++j)
if(invoke(pred, invoke(proj1, *i), invoke(proj2, *j)))
++c2;
if(c2 == 0)
return false;
// Count number of *i in [i, l1) (we can start with 1)
iter_difference_t<I1> c1 = 1;
for(I1 j = next(i); j != end1; ++j)
if(invoke(pred, invoke(proj1, *i), invoke(proj1, *j)))
++c1;
if(c1 != c2)
return false;
}
return true;
}
} // namespace detail
/// \endcond
RANGES_FUNC_BEGIN(is_permutation)
/// \brief function template \c is_permutation
template(typename I1,
typename S1,
typename I2,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)(
requires forward_iterator<I1> AND sentinel_for<S1, I1> AND
forward_iterator<I2> AND indirectly_comparable<I1, I2, C, P1, P2>)
RANGES_DEPRECATED(
"Use the variant of ranges::is_permutation that takes an upper bound "
"for both sequences")
bool RANGES_FUNC(is_permutation)(I1 begin1,
S1 end1,
I2 begin2,
C pred = C{},
P1 proj1 = P1{},
P2 proj2 = P2{}) //
{
// shorten sequences as much as possible by lopping off any equal parts
for(; begin1 != end1; ++begin1, ++begin2)
if(!invoke(pred, invoke(proj1, *begin1), invoke(proj2, *begin2)))
goto not_done;
return true;
not_done:
// begin1 != end1 && *begin1 != *begin2
auto l1 = distance(begin1, end1);
if(l1 == 1)
return false;
I2 end2 = next(begin2, l1);
// For each element in [f1, l1) see if there are the same number of
// equal elements in [f2, l2)
for(I1 i = begin1; i != end1; ++i)
{
// Have we already counted the number of *i in [f1, l1)?
for(I1 j = begin1; j != i; ++j)
if(invoke(pred, invoke(proj1, *j), invoke(proj1, *i)))
goto next_iter;
{
// Count number of *i in [f2, l2)
iter_difference_t<I2> c2 = 0;
for(I2 j = begin2; j != end2; ++j)
if(invoke(pred, invoke(proj1, *i), invoke(proj2, *j)))
++c2;
if(c2 == 0)
return false;
// Count number of *i in [i, l1) (we can start with 1)
iter_difference_t<I1> c1 = 1;
for(I1 j = next(i); j != end1; ++j)
if(invoke(pred, invoke(proj1, *i), invoke(proj1, *j)))
++c1;
if(c1 != c2)
return false;
}
next_iter:;
}
return true;
}
/// \overload
template(typename I1,
typename S1,
typename I2,
typename S2,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)(
requires forward_iterator<I1> AND sentinel_for<S1, I1> AND
forward_iterator<I2> AND sentinel_for<S2, I2> AND
indirectly_comparable<I1, I2, C, P1, P2>)
constexpr bool RANGES_FUNC(is_permutation)(I1 begin1,
S1 end1,
I2 begin2,
S2 end2,
C pred = C{},
P1 proj1 = P1{},
P2 proj2 = P2{}) //
{
if(RANGES_CONSTEXPR_IF(sized_sentinel_for<S1, I1> &&
sized_sentinel_for<S2, I2>))
{
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
return distance(begin1, end1) == distance(begin2, end2) &&
(*this)(std::move(begin1),
std::move(end1),
std::move(begin2),
std::move(pred),
std::move(proj1),
std::move(proj2));
RANGES_DIAGNOSTIC_POP
}
return detail::is_permutation_impl(std::move(begin1),
std::move(end1),
std::move(begin2),
std::move(end2),
std::move(pred),
std::move(proj1),
std::move(proj2));
}
/// \overload
template(typename Rng1,
typename I2Ref,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)(
requires forward_range<Rng1> AND forward_iterator<uncvref_t<I2Ref>> AND
indirectly_comparable<iterator_t<Rng1>, uncvref_t<I2Ref>, C, P1, P2>)
RANGES_DEPRECATED(
"Use the variant of ranges::is_permutation that takes an upper bound "
"for both sequences")
bool RANGES_FUNC(is_permutation)(Rng1 && rng1,
I2Ref && begin2,
C pred = C{},
P1 proj1 = P1{},
P2 proj2 = P2{}) //
{
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
return (*this)(begin(rng1),
end(rng1),
(I2Ref &&) begin2,
std::move(pred),
std::move(proj1),
std::move(proj2));
RANGES_DIAGNOSTIC_POP
}
/// \overload
template(typename Rng1,
typename Rng2,
typename C = equal_to,
typename P1 = identity,
typename P2 = identity)(
requires forward_range<Rng1> AND forward_range<Rng2> AND
indirectly_comparable<iterator_t<Rng1>, iterator_t<Rng2>, C, P1, P2>)
constexpr bool RANGES_FUNC(is_permutation)(
Rng1 && rng1, Rng2 && rng2, C pred = C{}, P1 proj1 = P1{}, P2 proj2 = P2{}) //
{
if(RANGES_CONSTEXPR_IF(sized_range<Rng1> && sized_range<Rng2>))
{
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
return distance(rng1) == distance(rng2) && (*this)(begin(rng1),
end(rng1),
begin(rng2),
std::move(pred),
std::move(proj1),
std::move(proj2));
RANGES_DIAGNOSTIC_POP
}
return detail::is_permutation_impl(begin(rng1),
end(rng1),
begin(rng2),
end(rng2),
std::move(pred),
std::move(proj1),
std::move(proj2));
}
RANGES_FUNC_END(is_permutation)
RANGES_FUNC_BEGIN(next_permutation)
/// \brief function template \c next_permutation
template(typename I, typename S, typename C = less, typename P = identity)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
sortable<I, C, P>)
constexpr bool RANGES_FUNC(next_permutation)(I first, S end_, C pred = C{}, P proj = P{}) //
{
if(first == end_)
return false;
I last = ranges::next(first, end_), i = last;
if(first == --i)
return false;
while(true)
{
I ip1 = i;
if(invoke(pred, invoke(proj, *--i), invoke(proj, *ip1)))
{
I j = last;
while(!invoke(pred, invoke(proj, *i), invoke(proj, *--j)))
;
ranges::iter_swap(i, j);
ranges::reverse(ip1, last);
return true;
}
if(i == first)
{
ranges::reverse(first, last);
return false;
}
}
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires bidirectional_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
constexpr bool RANGES_FUNC(next_permutation)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(next_permutation)
RANGES_FUNC_BEGIN(prev_permutation)
/// \brief function template \c prev_permutation
template(typename I, typename S, typename C = less, typename P = identity)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
sortable<I, C, P>)
constexpr bool RANGES_FUNC(prev_permutation)(I first, S end_, C pred = C{}, P proj = P{}) //
{
if(first == end_)
return false;
I last = ranges::next(first, end_), i = last;
if(first == --i)
return false;
while(true)
{
I ip1 = i;
if(invoke(pred, invoke(proj, *ip1), invoke(proj, *--i)))
{
I j = last;
while(!invoke(pred, invoke(proj, *--j), invoke(proj, *i)))
;
ranges::iter_swap(i, j);
ranges::reverse(ip1, last);
return true;
}
if(i == first)
{
ranges::reverse(first, last);
return false;
}
}
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires bidirectional_range<Rng> AND sortable<iterator_t<Rng>, C, P>)
constexpr bool RANGES_FUNC(prev_permutation)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(prev_permutation)
namespace cpp20
{
using ranges::is_permutation;
using ranges::next_permutation;
using ranges::prev_permutation;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,82 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REMOVE_HPP
#define RANGES_V3_ALGORITHM_REMOVE_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/find.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(remove)
/// \brief function template \c remove
template(typename I, typename S, typename T, typename P = identity)(
requires permutable<I> AND sentinel_for<S, I> AND
indirect_relation<equal_to, projected<I, P>, T const *>)
constexpr I RANGES_FUNC(remove)(I first, S last, T const & val, P proj = P{})
{
first = find(std::move(first), last, val, ranges::ref(proj));
if(first != last)
{
for(I i = next(first); i != last; ++i)
{
if(!(invoke(proj, *i) == val))
{
*first = iter_move(i);
++first;
}
}
}
return first;
}
/// \overload
template(typename Rng, typename T, typename P = identity)(
requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(remove)(Rng && rng, T const & val, P proj = P{})
{
return (*this)(begin(rng), end(rng), val, std::move(proj));
}
RANGES_FUNC_END(remove)
namespace cpp20
{
using ranges::remove;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,86 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REMOVE_COPY_HPP
#define RANGES_V3_ALGORITHM_REMOVE_COPY_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using remove_copy_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(remove_copy)
/// \brief function template \c remove_copy
template(typename I, typename S, typename O, typename T, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O> AND
indirect_relation<equal_to, projected<I, P>, T const *> AND
indirectly_copyable<I, O>)
constexpr remove_copy_result<I, O> RANGES_FUNC(remove_copy)(
I first, S last, O out, T const & val, P proj = P{}) //
{
for(; first != last; ++first)
{
auto && x = *first;
if(!(invoke(proj, x) == val))
{
*out = (decltype(x) &&)x;
++out;
}
}
return {first, out};
}
/// \overload
template(typename Rng, typename O, typename T, typename P = identity)(
requires input_range<Rng> AND weakly_incrementable<O> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *> AND
indirectly_copyable<iterator_t<Rng>, O>)
constexpr remove_copy_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(remove_copy)(Rng && rng, O out, T const & val, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(out), val, std::move(proj));
}
RANGES_FUNC_END(remove_copy)
namespace cpp20
{
using ranges::remove_copy;
using ranges::remove_copy_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,86 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REMOVE_COPY_IF_HPP
#define RANGES_V3_ALGORITHM_REMOVE_COPY_IF_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using remove_copy_if_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(remove_copy_if)
/// \brief function template \c remove_copy_if
template(typename I, typename S, typename O, typename C, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O> AND indirect_unary_predicate<C, projected<I, P>> AND
indirectly_copyable<I, O>)
constexpr remove_copy_if_result<I, O> //
RANGES_FUNC(remove_copy_if)(I first, S last, O out, C pred, P proj = P{}) //
{
for(; first != last; ++first)
{
auto && x = *first;
if(!(invoke(pred, invoke(proj, x))))
{
*out = (decltype(x) &&)x;
++out;
}
}
return {first, out};
}
/// \overload
template(typename Rng, typename O, typename C, typename P = identity)(
requires input_range<Rng> AND weakly_incrementable<O> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
indirectly_copyable<iterator_t<Rng>, O>)
constexpr remove_copy_if_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(remove_copy_if)(Rng && rng, O out, C pred, P proj = P{}) //
{
return (*this)(
begin(rng), end(rng), std::move(out), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(remove_copy_if)
namespace cpp20
{
using ranges::remove_copy_if;
using ranges::remove_copy_if_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,81 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REMOVE_IF_HPP
#define RANGES_V3_ALGORITHM_REMOVE_IF_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/find_if.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(remove_if)
/// \brief function template \c remove_if
template(typename I, typename S, typename C, typename P = identity)(
requires permutable<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr I RANGES_FUNC(remove_if)(I first, S last, C pred, P proj = P{})
{
first = find_if(std::move(first), last, ranges::ref(pred), ranges::ref(proj));
if(first != last)
{
for(I i = next(first); i != last; ++i)
{
if(!(invoke(pred, invoke(proj, *i))))
{
*first = iter_move(i);
++first;
}
}
}
return first;
}
/// \overload
template(typename Rng, typename C, typename P = identity)(
requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(remove_if)(Rng && rng, C pred, P proj = P{})
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(remove_if)
namespace cpp20
{
using ranges::remove_if;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,74 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REPLACE_HPP
#define RANGES_V3_ALGORITHM_REPLACE_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(replace)
/// \brief function template \c replace
template(typename I, typename S, typename T1, typename T2, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirectly_writable<I, T2 const &> AND
indirect_relation<equal_to, projected<I, P>, T1 const *>)
constexpr I RANGES_FUNC(replace)(
I first, S last, T1 const & old_value, T2 const & new_value, P proj = {}) //
{
for(; first != last; ++first)
if(invoke(proj, *first) == old_value)
*first = new_value;
return first;
}
/// \overload
template(typename Rng, typename T1, typename T2, typename P = identity)(
requires input_range<Rng> AND
indirectly_writable<iterator_t<Rng>, T2 const &> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T1 const *>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(replace)(
Rng && rng, T1 const & old_value, T2 const & new_value, P proj = {}) //
{
return (*this)(begin(rng), end(rng), old_value, new_value, std::move(proj));
}
RANGES_FUNC_END(replace)
namespace cpp20
{
using ranges::replace;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,102 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REPLACE_COPY_HPP
#define RANGES_V3_ALGORITHM_REPLACE_COPY_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using replace_copy_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(replace_copy)
/// \brief function template \c replace_copy
template(typename I,
typename S,
typename O,
typename T1,
typename T2,
typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
output_iterator<O, T2 const &> AND indirectly_copyable<I, O> AND
indirect_relation<equal_to, projected<I, P>, T1 const *>)
constexpr replace_copy_result<I, O> RANGES_FUNC(replace_copy)(I first,
S last,
O out,
T1 const & old_value,
T2 const & new_value,
P proj = {}) //
{
for(; first != last; ++first, ++out)
{
auto && x = *first;
if(invoke(proj, x) == old_value)
*out = new_value;
else
*out = (decltype(x) &&)x;
}
return {first, out};
}
/// \overload
template(typename Rng,
typename O,
typename T1,
typename T2,
typename P = identity)(
requires input_range<Rng> AND output_iterator<O, T2 const &> AND
indirectly_copyable<iterator_t<Rng>, O> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T1 const *>)
constexpr replace_copy_result<borrowed_iterator_t<Rng>, O> RANGES_FUNC(replace_copy)(
Rng && rng, O out, T1 const & old_value, T2 const & new_value, P proj = {}) //
{
return (*this)(begin(rng),
end(rng),
std::move(out),
old_value,
new_value,
std::move(proj));
}
RANGES_FUNC_END(replace_copy)
namespace cpp20
{
using ranges::replace_copy;
using ranges::replace_copy_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,95 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REPLACE_COPY_IF_HPP
#define RANGES_V3_ALGORITHM_REPLACE_COPY_IF_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using replace_copy_if_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(replace_copy_if)
/// \brief function template \c replace_copy_if
template(typename I,
typename S,
typename O,
typename C,
typename T,
typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
output_iterator<O, T const &> AND
indirect_unary_predicate<C, projected<I, P>> AND
indirectly_copyable<I, O>)
constexpr replace_copy_if_result<I, O> RANGES_FUNC(replace_copy_if)(
I first, S last, O out, C pred, T const & new_value, P proj = {}) //
{
for(; first != last; ++first, ++out)
{
auto && x = *first;
if(invoke(pred, invoke(proj, x)))
*out = new_value;
else
*out = (decltype(x) &&)x;
}
return {first, out};
}
/// \overload
template(typename Rng, typename O, typename C, typename T, typename P = identity)(
requires input_range<Rng> AND output_iterator<O, T const &> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
indirectly_copyable<iterator_t<Rng>, O>)
constexpr replace_copy_if_result<borrowed_iterator_t<Rng>, O> RANGES_FUNC(replace_copy_if)(
Rng && rng, O out, C pred, T const & new_value, P proj = {}) //
{
return (*this)(begin(rng),
end(rng),
std::move(out),
std::move(pred),
new_value,
std::move(proj));
}
RANGES_FUNC_END(replace_copy_if)
namespace cpp20
{
using ranges::replace_copy_if;
using ranges::replace_copy_if_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,75 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REPLACE_IF_HPP
#define RANGES_V3_ALGORITHM_REPLACE_IF_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(replace_if)
/// \brief function template \c replace_if
template(typename I, typename S, typename C, typename T, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<C, projected<I, P>> AND
indirectly_writable<I, T const &>)
constexpr I RANGES_FUNC(replace_if)(
I first, S last, C pred, T const & new_value, P proj = P{}) //
{
for(; first != last; ++first)
if(invoke(pred, invoke(proj, *first)))
*first = new_value;
return first;
}
/// \overload
template(typename Rng, typename C, typename T, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
indirectly_writable<iterator_t<Rng>, T const &>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(replace_if)(
Rng && rng, C pred, T const & new_value, P proj = P{}) //
{
return (*this)(
begin(rng), end(rng), std::move(pred), new_value, std::move(proj));
}
RANGES_FUNC_END(replace_if)
namespace cpp20
{
using ranges::replace_if;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,169 @@
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#ifndef RANGES_V3_ALGORITHM_RESULT_TYPES_HPP
#define RANGES_V3_ALGORITHM_RESULT_TYPES_HPP
#include <concepts/concepts.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
// Extensions: the dangling story actually works, and result structs
// are conditionally equality_comparable
#define RANGES_ALGO_RESULT_AUX_2(C, T1, M1, T2, M2) \
template(typename X, typename Y)( \
requires convertible_to<T1 const &, X> AND convertible_to<T2 const &, Y>) \
operator C<X, Y>() const & \
{ \
return {M1, M2}; \
} \
template(typename X, typename Y)( \
requires convertible_to<T1, X> AND convertible_to<T2, Y>) \
operator C<X, Y>() && \
{ \
return {static_cast<T1 &&>(M1), static_cast<T2 &&>(M2)}; \
} \
CPP_broken_friend_member \
friend constexpr auto operator==(C<T1, T2> const & x, C<T1, T2> const & y) \
-> CPP_broken_friend_ret(bool)( \
requires equality_comparable<T1> && equality_comparable<T2>) \
{ \
return x.M1 == y.M1 && x.M2 == y.M2; \
} \
CPP_broken_friend_member \
friend constexpr auto operator!=(C<T1, T2> const & x, C<T1, T2> const & y) \
-> CPP_broken_friend_ret(bool)( \
requires equality_comparable<T1> && equality_comparable<T2>) \
{ \
return !(x == y); \
} \
/**/
#define RANGES_ALGO_RESULT_AUX_3(C, T1, M1, T2, M2, T3, M3) \
template(typename X, typename Y, typename Z)( \
requires convertible_to<T1 const &, X> AND convertible_to<T2 const &, Y> AND \
convertible_to<T3 const &, Z>) \
operator C<X, Y, Z>() const & \
{ \
return {M1, M2, M3}; \
} \
template(typename X, typename Y, typename Z)( \
requires convertible_to<T1, X> AND convertible_to<T2, Y> AND \
convertible_to<T3, Z>) \
operator C<X, Y, Z>() && \
{ \
return {static_cast<T1 &&>(M1), static_cast<T2 &&>(M2), static_cast<T3 &&>(M3)}; \
} \
CPP_broken_friend_member \
friend constexpr auto operator==(C<T1, T2, T3> const & x, C<T1, T2, T3> const & y) \
-> CPP_broken_friend_ret(bool)( \
requires equality_comparable<T1> && equality_comparable<T2> && \
equality_comparable<T3>) \
{ \
return x.M1 == y.M1 && x.M2 == y.M2 && x.M3 == y.M3; \
} \
CPP_broken_friend_member \
friend constexpr auto operator!=(C<T1, T2, T3> const & x, C<T1, T2, T3> const & y) \
-> CPP_broken_friend_ret(bool)( \
requires equality_comparable<T1> && equality_comparable<T2> && \
equality_comparable<T3>) \
{ \
return !(x == y); \
} \
/**/
template<typename I, typename O>
struct in_out_result
{
I in;
O out;
RANGES_ALGO_RESULT_AUX_2(in_out_result, I, in, O, out)
};
template<typename I1, typename O>
struct in1_out_result
{
I1 in1;
O out;
RANGES_ALGO_RESULT_AUX_2(in1_out_result, I1, in1, O, out)
};
template<typename I1, typename I2>
struct in1_in2_result
{
I1 in1;
I2 in2;
RANGES_ALGO_RESULT_AUX_2(in1_in2_result, I1, in1, I2, in2)
};
template<typename I, typename Fun>
struct in_fun_result
{
I in;
Fun fun;
RANGES_ALGO_RESULT_AUX_2(in_fun_result, I, in, Fun, fun)
};
template<typename O, typename Fun>
struct out_fun_result
{
O out;
Fun fun;
RANGES_ALGO_RESULT_AUX_2(out_fun_result, O, out, Fun, fun)
};
template<typename T, typename U>
struct min_max_result
{
T min;
U max;
RANGES_ALGO_RESULT_AUX_2(min_max_result, T, min, U, max)
};
template<typename I1, typename I2, typename O>
struct in1_in2_out_result
{
I1 in1;
I2 in2;
O out;
RANGES_ALGO_RESULT_AUX_3(in1_in2_out_result, I1, in1, I2, in2, O, out)
};
template<typename I, typename O1, typename O2>
struct in_out1_out2_result
{
I in;
O1 out1;
O2 out2;
RANGES_ALGO_RESULT_AUX_3(in_out1_out2_result, I, in, O1, out1, O2, out2)
};
} // namespace detail
/// \endcond
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,91 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REVERSE_HPP
#define RANGES_V3_ALGORITHM_REVERSE_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// \cond
namespace detail
{
template<typename I>
constexpr void reverse_impl(I first, I last, std::bidirectional_iterator_tag)
{
while(first != last)
{
if(first == --last)
break;
ranges::iter_swap(first, last);
++first;
}
}
template<typename I>
constexpr void reverse_impl(I first, I last, std::random_access_iterator_tag)
{
if(first != last)
for(; first < --last; ++first)
ranges::iter_swap(first, last);
}
} // namespace detail
/// \endcond
RANGES_FUNC_BEGIN(reverse)
/// \brief function template \c reverse
template(typename I, typename S)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND permutable<I>)
constexpr I RANGES_FUNC(reverse)(I first, S end_)
{
I last = ranges::next(first, end_);
detail::reverse_impl(first, last, iterator_tag_of<I>{});
return last;
}
/// \overload
template(typename Rng, typename I = iterator_t<Rng>)(
requires bidirectional_range<Rng> AND permutable<I>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(reverse)(Rng && rng) //
{
return (*this)(begin(rng), end(rng));
}
RANGES_FUNC_END(reverse)
namespace cpp20
{
using ranges::reverse;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,75 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REVERSE_COPY_HPP
#define RANGES_V3_ALGORITHM_REVERSE_COPY_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using reverse_copy_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(reverse_copy)
/// \brief function template \c reverse_copy
template(typename I, typename S, typename O)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O> AND indirectly_copyable<I, O>)
constexpr reverse_copy_result<I, O> RANGES_FUNC(reverse_copy)(I first, S end_, O out) //
{
I last = ranges::next(first, end_), res = last;
for(; first != last; ++out)
*out = *--last;
return {res, out};
}
/// \overload
template(typename Rng, typename O)(
requires bidirectional_range<Rng> AND weakly_incrementable<O> AND
indirectly_copyable<iterator_t<Rng>, O>)
constexpr reverse_copy_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(reverse_copy)(Rng && rng, O out) //
{
return (*this)(begin(rng), end(rng), std::move(out));
}
RANGES_FUNC_END(reverse_copy)
namespace cpp20
{
using ranges::reverse_copy;
using ranges::reverse_copy_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

View File

@@ -0,0 +1,234 @@
/// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_ROTATE_HPP
#define RANGES_V3_ALGORITHM_ROTATE_HPP
#include <type_traits>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/move.hpp>
#include <range/v3/algorithm/move_backward.hpp>
#include <range/v3/algorithm/swap_ranges.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/move.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/view/subrange.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// \cond
namespace detail
{
template<typename I> // Forward
constexpr subrange<I> rotate_left(I first, I last)
{
iter_value_t<I> tmp = iter_move(first);
I lm1 = ranges::move(next(first), last, first).out;
*lm1 = std::move(tmp);
return {lm1, last};
}
template<typename I> // Bidirectional
constexpr subrange<I> rotate_right(I first, I last)
{
I lm1 = prev(last);
iter_value_t<I> tmp = iter_move(lm1);
I fp1 = move_backward(first, lm1, last).out;
*first = std::move(tmp);
return {fp1, last};
}
template<typename I, typename S> // Forward
constexpr subrange<I> rotate_forward(I first, I middle, S last)
{
I i = middle;
while(true)
{
ranges::iter_swap(first, i);
++first;
if(++i == last)
break;
if(first == middle)
middle = i;
}
I r = first;
if(first != middle)
{
I j = middle;
while(true)
{
ranges::iter_swap(first, j);
++first;
if(++j == last)
{
if(first == middle)
break;
j = middle;
}
else if(first == middle)
middle = j;
}
}
return {r, i};
}
template<typename D>
constexpr D gcd(D x, D y)
{
do
{
D t = x % y;
x = y;
y = t;
} while(y);
return x;
}
template<typename I> // Random
constexpr subrange<I> rotate_gcd(I first, I middle, I last)
{
auto const m1 = middle - first;
auto const m2 = last - middle;
if(m1 == m2)
{
swap_ranges(first, middle, middle);
return {middle, last};
}
auto const g = detail::gcd(m1, m2);
for(I p = first + g; p != first;)
{
iter_value_t<I> t = iter_move(--p);
I p1 = p;
I p2 = p1 + m1;
do
{
*p1 = iter_move(p2);
p1 = p2;
auto const d = last - p2;
if(m1 < d)
p2 += m1;
else
p2 = first + (m1 - d);
} while(p2 != p);
*p1 = std::move(t);
}
return {first + m2, last};
}
template<typename I, typename S>
constexpr subrange<I> rotate_(I first, I middle, S last, std::forward_iterator_tag)
{
return detail::rotate_forward(first, middle, last);
}
template<typename I>
constexpr subrange<I> rotate_(I first, I middle, I last, std::forward_iterator_tag)
{
using value_type = iter_value_t<I>;
if(detail::is_trivially_move_assignable_v<value_type>)
{
if(next(first) == middle)
return detail::rotate_left(first, last);
}
return detail::rotate_forward(first, middle, last);
}
template<typename I>
constexpr subrange<I> rotate_(I first, I middle, I last, std::bidirectional_iterator_tag)
{
using value_type = iter_value_t<I>;
if(detail::is_trivially_move_assignable_v<value_type>)
{
if(next(first) == middle)
return detail::rotate_left(first, last);
if(next(middle) == last)
return detail::rotate_right(first, last);
}
return detail::rotate_forward(first, middle, last);
}
template<typename I>
constexpr subrange<I> rotate_(I first, I middle, I last, std::random_access_iterator_tag)
{
using value_type = iter_value_t<I>;
if(detail::is_trivially_move_assignable_v<value_type>)
{
if(next(first) == middle)
return detail::rotate_left(first, last);
if(next(middle) == last)
return detail::rotate_right(first, last);
return detail::rotate_gcd(first, middle, last);
}
return detail::rotate_forward(first, middle, last);
}
} // namespace detail
/// \endcond
RANGES_FUNC_BEGIN(rotate)
/// \brief function template \c rotate
template(typename I, typename S)(
requires permutable<I> AND sentinel_for<S, I>)
constexpr subrange<I> RANGES_FUNC(rotate)(I first, I middle, S last) //
{
if(first == middle)
{
first = ranges::next(std::move(first), last);
return {first, first};
}
if(middle == last)
{
return {first, middle};
}
return detail::rotate_(first, middle, last, iterator_tag_of<I>{});
}
/// \overload
template(typename Rng, typename I = iterator_t<Rng>)(
requires range<Rng> AND permutable<I>)
constexpr borrowed_subrange_t<Rng> RANGES_FUNC(rotate)(Rng && rng, I middle) //
{
return (*this)(begin(rng), std::move(middle), end(rng));
}
RANGES_FUNC_END(rotate)
namespace cpp20
{
using ranges::rotate;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif

Some files were not shown because too many files have changed in this diff Show More