This file is indexed.

/usr/include/range/v3/view/concat.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/// \file
// Range v3 library
//
//  Copyright Eric Niebler 2013-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_VIEW_CONCAT_HPP
#define RANGES_V3_VIEW_CONCAT_HPP

#include <tuple>
#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/range_traits.hpp>
#include <range/v3/range_concepts.hpp>
#include <range/v3/view_facade.hpp>
#include <range/v3/utility/variant.hpp>
#include <range/v3/utility/iterator.hpp>
#include <range/v3/utility/functional.hpp>
#include <range/v3/utility/tuple_algorithm.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/all.hpp>

namespace ranges
{
    inline namespace v3
    {
        /// \cond
        namespace detail
        {
            template<typename State, typename Value>
            using concat_cardinality_ =
                std::integral_constant<cardinality,
                    State::value == infinite || Value::value == infinite ?
                        infinite :
                        State::value == unknown || Value::value == unknown ?
                            unknown :
                            State::value == finite || Value::value == finite ?
                                finite :
                                static_cast<cardinality>(State::value + Value::value)>;

            template<typename... Rngs>
            using concat_cardinality = meta::fold<
                meta::list<range_cardinality<Rngs>...>,
                std::integral_constant<cardinality, static_cast<cardinality>(0)>,
                meta::quote<concat_cardinality_>>;
        }
        /// \endcond

        /// \addtogroup group-views
        /// @{
        template<typename...Rngs>
        struct concat_view
          : view_facade<concat_view<Rngs...>,
                detail::concat_cardinality<Rngs...>::value>
        {
        private:
            friend range_access;
            using difference_type_ = common_type_t<range_difference_type_t<Rngs>...>;
            using size_type_ = meta::_t<std::make_unsigned<difference_type_>>;
            static constexpr std::size_t cranges{sizeof...(Rngs)};
            std::tuple<Rngs...> rngs_;

            template<bool IsConst>
            struct cursor;

            template<bool IsConst>
            struct sentinel
            {
            private:
                friend struct cursor<IsConst>;
                template<typename T>
                using constify_if = meta::const_if_c<IsConst, T>;
                using concat_view_t = constify_if<concat_view>;
                sentinel_t<constify_if<meta::back<meta::list<Rngs...>>>> end_;
            public:
                sentinel() = default;
                sentinel(concat_view_t &rng, end_tag)
                  : end_(end(std::get<cranges - 1>(rng.rngs_)))
                {}
            };

            template<bool IsConst>
            struct cursor
            {
                using difference_type = common_type_t<range_difference_type_t<Rngs>...>;
            private:
                template<typename T>
                using constify_if = meta::const_if_c<IsConst, T>;
                using concat_view_t = constify_if<concat_view>;
                concat_view_t *rng_;
                variant<iterator_t<constify_if<Rngs>>...> its_;

                template<std::size_t N>
                void satisfy(meta::size_t<N>)
                {
                    RANGES_EXPECT(its_.index() == N);
                    if(ranges::get<N>(its_) == end(std::get<N>(rng_->rngs_)))
                    {
                        ranges::emplace<N + 1>(its_, begin(std::get<N + 1>(rng_->rngs_)));
                        this->satisfy(meta::size_t<N + 1>{});
                    }
                }
                void satisfy(meta::size_t<cranges - 1>)
                {
                    RANGES_EXPECT(its_.index() == cranges - 1);
                }
                struct next_fun
                {
                    cursor *pos;
                    template<typename I, std::size_t N,
                        CONCEPT_REQUIRES_(Iterator<I>())>
                    void operator()(indexed_element<I, N> it) const
                    {
                        RANGES_ASSERT(it.get() != end(std::get<N>(pos->rng_->rngs_)));
                        ++it.get();
                        pos->satisfy(meta::size_t<N>{});
                    }
                };
                struct prev_fun
                {
                    cursor *pos;
                    template<typename I,
                        CONCEPT_REQUIRES_(BidirectionalIterator<I>())>
                    void operator()(indexed_element<I, 0> it) const
                    {
                        RANGES_ASSERT(it.get() != begin(std::get<0>(pos->rng_->rngs_)));
                        --it.get();
                    }
                    template<typename I, std::size_t N,
                        CONCEPT_REQUIRES_(N != 0 && BidirectionalIterator<I>())>
                    void operator()(indexed_element<I, N> it) const
                    {
                        if(it.get() == begin(std::get<N>(pos->rng_->rngs_)))
                        {
                            auto &&rng = std::get<N - 1>(pos->rng_->rngs_);
                            ranges::emplace<N - 1>(pos->its_,
                                ranges::next(ranges::begin(rng), ranges::end(rng)));
                            pos->its_.visit_i(*this);
                        }
                        else
                            --it.get();
                    }
                };
                struct advance_fwd_fun
                {
                    cursor *pos;
                    difference_type n;
                    template<typename I,
                        CONCEPT_REQUIRES_(RandomAccessIterator<I>())>
                    void operator()(indexed_element<I, cranges - 1> it) const
                    {
                        ranges::advance(it.get(), n);
                    }
                    template<typename I, std::size_t N,
                        CONCEPT_REQUIRES_(RandomAccessIterator<I>())>
                    void operator()(indexed_element<I, N> it) const
                    {
                        auto end = ranges::end(std::get<N>(pos->rng_->rngs_));
                        // BUGBUG If distance(it, end) > n, then using bounded advance
                        // is O(n) when it need not be since the end iterator position
                        // is actually not interesting. Only the "rest" is needed, which
                        // can sometimes be O(1).
                        auto rest = ranges::advance(it.get(), n, std::move(end));
                        pos->satisfy(meta::size_t<N>{});
                        if(rest != 0)
                            pos->its_.visit_i(advance_fwd_fun{pos, rest});
                    }
                };
                struct advance_rev_fun
                {
                    cursor *pos;
                    difference_type n;
                    template<typename I,
                        CONCEPT_REQUIRES_(RandomAccessIterator<I>())>
                    void operator()(indexed_element<I, 0> it) const
                    {
                        ranges::advance(it.get(), n);
                    }
                    template<typename I, std::size_t N,
                        CONCEPT_REQUIRES_(RandomAccessIterator<I>())>
                    void operator()(indexed_element<I, N> it) const
                    {
                        auto begin = ranges::begin(std::get<N>(pos->rng_->rngs_));
                        if(it.get() == begin)
                        {
                            auto &&rng = std::get<N - 1>(pos->rng_->rngs_);
                            ranges::emplace<N - 1>(pos->its_,
                                ranges::next(ranges::begin(rng), ranges::end(rng)));
                            pos->its_.visit_i(*this);
                        }
                        else
                        {
                            auto rest = ranges::advance(it.get(), n, std::move(begin));
                            if(rest != 0)
                                pos->its_.visit_i(advance_rev_fun{pos, rest});
                        }
                    }
                };
                [[noreturn]] static difference_type distance_to_(meta::size_t<cranges>, cursor const &, cursor const &)
                {
                    RANGES_EXPECT(false);
                }
                template<std::size_t N>
                static difference_type distance_to_(meta::size_t<N>, cursor const &from, cursor const &to)
                {
                    if(from.its_.index() > N)
                        return cursor::distance_to_(meta::size_t<N + 1>{}, from, to);
                    if(from.its_.index() == N)
                    {
                        if(to.its_.index() == N)
                            return distance(ranges::get<N>(from.its_), ranges::get<N>(to.its_));
                        return distance(ranges::get<N>(from.its_), end(std::get<N>(from.rng_->rngs_))) +
                            cursor::distance_to_(meta::size_t<N + 1>{}, from, to);
                    }
                    if(from.its_.index() < N && to.its_.index() > N)
                        return distance(std::get<N>(from.rng_->rngs_)) +
                            cursor::distance_to_(meta::size_t<N + 1>{}, from, to);
                    RANGES_EXPECT(to.its_.index() == N);
                    return distance(begin(std::get<N>(from.rng_->rngs_)), ranges::get<N>(to.its_));
                }
            public:
                // BUGBUG what about rvalue_reference and common_reference?
                using reference = common_reference_t<range_reference_t<constify_if<Rngs>>...>;
                using single_pass = meta::strict_or<SinglePass<iterator_t<Rngs>>...>;
                cursor() = default;
                cursor(concat_view_t &rng, begin_tag)
                  : rng_(&rng), its_{emplaced_index<0>, begin(std::get<0>(rng.rngs_))}
                {
                    this->satisfy(meta::size_t<0>{});
                }
                cursor(concat_view_t &rng, end_tag)
                  : rng_(&rng), its_{emplaced_index<cranges-1>, end(std::get<cranges-1>(rng.rngs_))}
                {}
                reference read() const
                {
                    // Kind of a dumb implementation. Surely there's a better way.
                    return ranges::get<0>(unique_variant(its_.visit(
                        compose(convert_to<reference>{}, dereference_fn{}))));
                }
                void next()
                {
                    its_.visit_i(next_fun{this});
                }
                CONCEPT_REQUIRES(EqualityComparable<decltype(its_)>())
                bool equal(cursor const &pos) const
                {
                    return its_ == pos.its_;
                }
                bool equal(sentinel<IsConst> const &pos) const
                {
                    return its_.index() == cranges - 1 &&
                        ranges::get<cranges - 1>(its_) == pos.end_;
                }
                CONCEPT_REQUIRES(meta::and_c<(bool)BidirectionalRange<Rngs>()...>::value)
                void prev()
                {
                    its_.visit_i(prev_fun{this});
                }
                CONCEPT_REQUIRES(meta::and_c<(bool)RandomAccessRange<Rngs>()...>::value)
                void advance(difference_type n)
                {
                    if(n > 0)
                        its_.visit_i(advance_fwd_fun{this, n});
                    else if(n < 0)
                        its_.visit_i(advance_rev_fun{this, n});
                }
                CONCEPT_REQUIRES(meta::and_c<(bool)
                    SizedSentinel<iterator_t<Rngs>, iterator_t<Rngs>>()...>::value)
                difference_type distance_to(cursor const &that) const
                {
                    if(its_.index() <= that.its_.index())
                        return cursor::distance_to_(meta::size_t<0>{}, *this, that);
                    return -cursor::distance_to_(meta::size_t<0>{}, that, *this);
                }
            };
            cursor<false> begin_cursor()
            {
                return {*this, begin_tag{}};
            }
            meta::if_<meta::and_c<(bool)BoundedRange<Rngs>()...>, cursor<false>, sentinel<false>>
            end_cursor()
            {
                return {*this, end_tag{}};
            }
            CONCEPT_REQUIRES(meta::and_c<(bool)Range<Rngs const>()...>())
            cursor<true> begin_cursor() const
            {
                return {*this, begin_tag{}};
            }
            CONCEPT_REQUIRES(meta::and_c<(bool)Range<Rngs const>()...>())
            meta::if_<meta::and_c<(bool)BoundedRange<Rngs>()...>, cursor<true>, sentinel<true>>
            end_cursor() const
            {
                return {*this, end_tag{}};
            }
        public:
            concat_view() = default;
            explicit concat_view(Rngs...rngs)
              : rngs_{std::move(rngs)...}
            {}
            CONCEPT_REQUIRES(detail::concat_cardinality<Rngs...>::value >= 0)
            constexpr size_type_ size() const
            {
                return static_cast<size_type_>(detail::concat_cardinality<Rngs...>::value);
            }
            CONCEPT_REQUIRES(detail::concat_cardinality<Rngs...>::value < 0 &&
                meta::and_c<(bool)SizedRange<Rngs const>()...>::value)
            RANGES_CXX14_CONSTEXPR size_type_ size() const
            {
                return const_cast<concat_view *>(this)->size();
            }
            CONCEPT_REQUIRES(detail::concat_cardinality<Rngs...>::value < 0 &&
                meta::and_c<(bool)SizedRange<Rngs>()...>::value)
            RANGES_CXX14_CONSTEXPR size_type_ size()
            {
                return tuple_foldl(tuple_transform(rngs_, ranges::size), size_type_{0}, plus{});
            }
        };

        namespace view
        {
            struct concat_fn
            {
                template<typename...Rngs>
                concat_view<all_t<Rngs>...> operator()(Rngs &&... rngs) const
                {
                    static_assert(meta::and_c<(bool)InputRange<Rngs>()...>::value,
                        "Expecting Input Ranges");
                    return concat_view<all_t<Rngs>...>{all(static_cast<Rngs&&>(rngs))...};
                }
            };

            /// \relates concat_fn
            /// \ingroup group-views
            RANGES_INLINE_VARIABLE(concat_fn, concat)
        }
        /// @}
    }
}

RANGES_SATISFY_BOOST_RANGE(::ranges::v3::concat_view)

#endif