/usr/include/range/v3/view/drop.hpp is in librange-v3-dev 0.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | /// \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_DROP_HPP
#define RANGES_V3_VIEW_DROP_HPP
#include <type_traits>
#include <meta/meta.hpp>
#include <range/v3/iterator_range.hpp>
#include <range/v3/range_concepts.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/range_traits.hpp>
#include <range/v3/view_interface.hpp>
#include <range/v3/detail/satisfy_boost_range.hpp>
#include <range/v3/utility/box.hpp>
#include <range/v3/utility/functional.hpp>
#include <range/v3/utility/iterator_traits.hpp>
#include <range/v3/utility/optional.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/all.hpp>
#include <range/v3/view/view.hpp>
namespace ranges
{
inline namespace v3
{
/// \addtogroup group-views
/// @{
template<typename Rng>
struct drop_view
: view_interface<drop_view<Rng>, is_finite<Rng>::value ? finite : range_cardinality<Rng>::value>
, private detail::non_propagating_cache<
iterator_t<Rng>,
drop_view<Rng>,
!RandomAccessRange<Rng>()>
{
private:
friend range_access;
using difference_type_ = range_difference_type_t<Rng>;
Rng rng_;
difference_type_ n_;
template<typename BaseRng = Rng>
iterator_t<BaseRng const> get_begin_(std::true_type, std::true_type) const
{
CONCEPT_ASSERT(RandomAccessRange<Rng const>());
return next(ranges::begin(rng_), n_, ranges::end(rng_));
}
iterator_t<Rng> get_begin_(std::true_type, std::false_type)
{
CONCEPT_ASSERT(RandomAccessRange<Rng>());
return next(ranges::begin(rng_), n_, ranges::end(rng_));
}
iterator_t<Rng> get_begin_(std::false_type, detail::any)
{
CONCEPT_ASSERT(!RandomAccessRange<Rng>());
using cache_t = detail::non_propagating_cache<
iterator_t<Rng>, drop_view<Rng>>;
auto &begin_ = static_cast<cache_t&>(*this);
if(!begin_)
begin_ = next(ranges::begin(rng_), n_, ranges::end(rng_));
return *begin_;
}
public:
drop_view() = default;
drop_view(Rng rng, difference_type_ n)
: rng_(std::move(rng)), n_(n)
{
RANGES_EXPECT(n >= 0);
}
CONCEPT_REQUIRES(!RandomAccessRange<Rng const>())
iterator_t<Rng> begin()
{
return this->get_begin_(RandomAccessRange<Rng>{}, std::false_type{});
}
CONCEPT_REQUIRES(!RandomAccessRange<Rng const>())
sentinel_t<Rng> end()
{
return ranges::end(rng_);
}
template<typename BaseRng = Rng,
CONCEPT_REQUIRES_(RandomAccessRange<BaseRng const>())>
iterator_t<BaseRng const> begin() const
{
return this->get_begin_(std::true_type{}, std::true_type{});
}
template<typename BaseRng = Rng,
CONCEPT_REQUIRES_(RandomAccessRange<BaseRng const>())>
sentinel_t<BaseRng const> end() const
{
return ranges::end(rng_);
}
CONCEPT_REQUIRES(SizedRange<Rng const>())
range_size_type_t<Rng> size() const
{
auto const s = static_cast<range_size_type_t<Rng>>(ranges::size(rng_));
auto const n = static_cast<range_size_type_t<Rng>>(n_);
return s < n ? 0 : s - n;
}
CONCEPT_REQUIRES(!SizedRange<Rng const>() && SizedRange<Rng>())
range_size_type_t<Rng> size()
{
auto const s = static_cast<range_size_type_t<Rng>>(ranges::size(rng_));
auto const n = static_cast<range_size_type_t<Rng>>(n_);
return s < n ? 0 : s - n;
}
Rng & base()
{
return rng_;
}
Rng const & base() const
{
return rng_;
}
};
namespace view
{
struct drop_fn
{
private:
friend view_access;
template<typename Int,
CONCEPT_REQUIRES_(Integral<Int>())>
static auto bind(drop_fn drop, Int n)
RANGES_DECLTYPE_AUTO_RETURN
(
make_pipeable(std::bind(drop, std::placeholders::_1, n))
)
#ifndef RANGES_DOXYGEN_INVOKED
template<typename Int,
CONCEPT_REQUIRES_(!Integral<Int>())>
static detail::null_pipe bind(drop_fn, Int)
{
CONCEPT_ASSERT_MSG(Integral<Int>(),
"The object passed to view::drop must be Integral");
return {};
}
#endif
template<typename Rng>
static drop_view<all_t<Rng>>
invoke_(Rng && rng, range_difference_type_t<Rng> n, concepts::InputRange*)
{
return {all(static_cast<Rng&&>(rng)), n};
}
template<typename Rng, CONCEPT_REQUIRES_(!View<uncvref_t<Rng>>() && std::is_lvalue_reference<Rng>())>
static iterator_range<iterator_t<Rng>, sentinel_t<Rng>>
invoke_(Rng && rng, range_difference_type_t<Rng> n, concepts::RandomAccessRange*)
{
return {next(begin(rng), n), end(rng)};
}
public:
template<typename Rng,
CONCEPT_REQUIRES_(InputRange<Rng>())>
auto operator()(Rng && rng, range_difference_type_t<Rng> n) const
RANGES_DECLTYPE_AUTO_RETURN
(
drop_fn::invoke_(static_cast<Rng&&>(rng), n, range_concept<Rng>{})
)
#ifndef RANGES_DOXYGEN_INVOKED
template<typename Rng, typename T,
CONCEPT_REQUIRES_(!(InputRange<Rng>() && Integral<T>()))>
void operator()(Rng &&, T) const
{
CONCEPT_ASSERT_MSG(InputRange<Rng>(),
"The first argument to view::drop must be a model of the InputRange concept");
CONCEPT_ASSERT_MSG(Integral<T>(),
"The second argument to view::drop must be a model of the Integral concept");
}
#endif
};
/// \relates drop_fn
/// \ingroup group-views
RANGES_INLINE_VARIABLE(view<drop_fn>, drop)
}
/// @}
}
}
RANGES_SATISFY_BOOST_RANGE(::ranges::v3::drop_view)
#endif
|