This file is indexed.

/usr/include/range/v3/view/cycle.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/// \file cycle.hpp
// Range v3 library
//
//  Copyright Eric Niebler 2013-present
//  Copyright Gonzalo Brito Gadeschi 2015
//  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_VIEW_CYCLE_HPP
#define RANGES_V3_VIEW_CYCLE_HPP

#include <utility>
#include <type_traits>
#include <meta/meta.hpp>
#include <range/v3/detail/satisfy_boost_range.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/size.hpp>
#include <range/v3/begin_end.hpp>
#include <range/v3/empty.hpp>
#include <range/v3/range_traits.hpp>
#include <range/v3/range_concepts.hpp>
#include <range/v3/view_facade.hpp>
#include <range/v3/view/all.hpp>
#include <range/v3/view/view.hpp>
#include <range/v3/utility/box.hpp>
#include <range/v3/utility/get.hpp>
#include <range/v3/utility/iterator.hpp>
#include <range/v3/utility/optional.hpp>
#include <range/v3/utility/static_const.hpp>

namespace ranges
{
    inline namespace v3
    {
        /// \addtogroup group-views
        ///@{
        template<typename Rng>
        struct cycled_view
          : view_facade<cycled_view<Rng>, infinite>
          , private detail::non_propagating_cache<
                iterator_t<Rng>, cycled_view<Rng>, !BoundedRange<Rng>()>
        {
        private:
            CONCEPT_ASSERT(ForwardRange<Rng>());
            friend range_access;
            Rng rng_;

            using cache_t = detail::non_propagating_cache<
                iterator_t<Rng>, cycled_view<Rng>, !BoundedRange<Rng>()>;

            template<bool IsConst>
            struct cursor
            {
            private:
                template<typename T>
                using constify_if = meta::const_if_c<IsConst, T>;
                using cycled_view_t = constify_if<cycled_view>;
                using difference_type_ = range_difference_type_t<Rng>;
                using iterator = iterator_t<constify_if<Rng>>;

                cycled_view_t *rng_;
                iterator it_;

                iterator get_end_(std::true_type, bool = false) const
                {
                    return ranges::end(rng_->rng_);
                }
                template<bool CanBeEmpty = false>
                iterator get_end_(std::false_type, meta::bool_<CanBeEmpty> = {}) const
                {
                    auto &end_ = static_cast<cache_t&>(*rng_);
                    RANGES_EXPECT(CanBeEmpty || end_);
                    if(CanBeEmpty && !end_)
                        end_ = ranges::next(it_, ranges::end(rng_->rng_));
                    return *end_;
                }
                void set_end_(std::true_type) const
                {}
                void set_end_(std::false_type) const
                {
                    auto &end_ = static_cast<cache_t&>(*rng_);
                    if(!end_)
                        end_ = it_;
                }
            public:
                cursor()
                  : rng_{}, it_{}
                {}
                explicit cursor(cycled_view_t &rng)
                  : rng_(&rng), it_(ranges::begin(rng.rng_))
                {}
                constexpr bool equal(default_sentinel) const
                {
                    return false;
                }
                auto read() const
                RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
                (
                    *it_
                )
                bool equal(cursor const &pos) const
                {
                    RANGES_EXPECT(rng_ == pos.rng_);
                    return it_ == pos.it_;
                }
                void next()
                {
                    auto const end = ranges::end(rng_->rng_);
                    RANGES_EXPECT(it_ != end);
                    if(++it_ == end)
                    {
                        this->set_end_(BoundedRange<Rng>());
                        it_ = ranges::begin(rng_->rng_);
                    }
                }
                CONCEPT_REQUIRES(BidirectionalRange<Rng>())
                void prev()
                {
                    if(it_ == ranges::begin(rng_->rng_))
                        it_ = this->get_end_(BoundedRange<Rng>());
                    --it_;
                }
                CONCEPT_REQUIRES(RandomAccessRange<Rng>())
                void advance(difference_type_ n)
                {
                    auto const begin = ranges::begin(rng_->rng_);
                    auto const end = this->get_end_(BoundedRange<Rng>(), meta::bool_<true>());
                    auto const d = end - begin;
                    auto const off = ((it_ - begin) + n) % d;
                    it_ = begin + (off < 0 ? off + d : off);
                }
                CONCEPT_REQUIRES(SizedSentinel<iterator, iterator>())
                difference_type_ distance_to(cursor const &that) const
                {
                    RANGES_EXPECT(that.rng_ == rng_);
                    return that.it_ - it_;
                }
            };

            cursor<false> begin_cursor()
            {
                return cursor<false>{*this};
            }
            CONCEPT_REQUIRES(BoundedRange<Rng const>())
            cursor<true> begin_cursor() const
            {
                return cursor<true>{*this};
            }

        public:
            cycled_view() = default;
            /// \pre <tt>!empty(rng)</tt>
            explicit cycled_view(Rng rng)
              : rng_(std::move(rng))
            {
                RANGES_EXPECT(!ranges::empty(rng_));
            }
        };

        namespace view
        {
            /// Returns an infinite range that endlessly repeats the source
            /// range.
            struct cycle_fn
            {
            private:
                friend view_access;
                template<class T>
                using Concept = ForwardRange<T>;

            public:
                /// \pre <tt>!empty(rng)</tt>
                template<typename Rng, CONCEPT_REQUIRES_(Concept<Rng>())>
                cycled_view<all_t<Rng>> operator()(Rng &&rng) const
                {
                    return cycled_view<all_t<Rng>>{all(static_cast<Rng&&>(rng))};
                }

#ifndef RANGES_DOXYGEN_INVOKED
                template<typename Rng, CONCEPT_REQUIRES_(!Concept<Rng>())>
                void operator()(Rng &&) const
                {
                    CONCEPT_ASSERT_MSG(ForwardRange<Rng>(),
                        "The object on which view::cycle operates must be a "
                        "model of the ForwardRange concept.");
                }
#endif
            };

            /// \relates cycle_fn
            /// \ingroup group-views
            RANGES_INLINE_VARIABLE(view<cycle_fn>, cycle)
       } // namespace view
       /// @}
    } // namespace v3
} // namespace ranges

RANGES_SATISFY_BOOST_RANGE(::ranges::v3::cycled_view)

#endif