/// \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_VIEW_DELIMIT_HPP
#define RANGES_V3_VIEW_DELIMIT_HPP
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace ranges
{
/// \addtogroup group-views
/// @{
template
struct delimit_view
: view_adaptor, Rng,
is_finite::value ? finite : unknown>
{
private:
friend range_access;
Val value_;
struct sentinel_adaptor : adaptor_base
{
sentinel_adaptor() = default;
sentinel_adaptor(Val value)
: value_(std::move(value))
{}
template
bool empty(I const & it, S const & last) const
{
return it == last || *it == value_;
}
Val value_;
};
sentinel_adaptor end_adaptor() const
{
return {value_};
}
public:
delimit_view() = default;
constexpr delimit_view(Rng rng, Val value)
: delimit_view::view_adaptor{std::move(rng)}
, value_(std::move(value))
{}
};
// the begin iterator will be an iterator into the underlying view (conditionally
// borrowed) and the end iterator owns the value to be compared against (borrowed)
template
RANGES_INLINE_VAR constexpr bool enable_borrowed_range> = //
enable_borrowed_range;
#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
template(typename Rng, typename Val)(
requires copy_constructible)
delimit_view(Rng &&, Val)
-> delimit_view, Val>;
#endif
namespace views
{
struct delimit_base_fn
{
template(typename I_, typename Val, typename I = detail::decay_t)(
requires (!range) AND convertible_to AND input_iterator AND
semiregular AND
equality_comparable_with>)
constexpr auto operator()(I_ && begin_, Val value) const
-> delimit_view, Val>
{
return {{static_cast(begin_), {}}, std::move(value)};
}
template(typename Rng, typename Val)(
requires viewable_range AND input_range AND semiregular<
Val> AND equality_comparable_with>)
constexpr auto operator()(Rng && rng, Val value) const //
-> delimit_view, Val>
{
return {all(static_cast(rng)), std::move(value)};
}
};
struct delimit_fn : delimit_base_fn
{
using delimit_base_fn::operator();
template
constexpr auto operator()(Val value) const
{
return make_view_closure(bind_back(delimit_base_fn{}, std::move(value)));
}
};
/// \relates delimit_fn
/// \ingroup group-views
RANGES_INLINE_VARIABLE(delimit_fn, delimit)
} // namespace views
/// @}
} // namespace ranges
#include
#include
RANGES_SATISFY_BOOST_RANGE(::ranges::delimit_view)
#endif