/usr/include/range/v3/view/generate.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 | /// \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_VIEW_GENERATE_HPP
#define RANGES_V3_VIEW_GENERATE_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/range_traits.hpp>
#include <range/v3/view_facade.hpp>
#include <range/v3/utility/functional.hpp>
#include <range/v3/utility/semiregular.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/unreachable.hpp>
namespace ranges
{
inline namespace v3
{
/// \addtogroup group-views
/// @{
template<typename G>
struct generate_view
: view_facade<generate_view<G>, infinite>
{
private:
friend range_access;
using result_t = result_of_t<G&()>;
movesemiregular_t<G> gen_;
movesemiregular_t<result_t> val_;
struct cursor
{
private:
generate_view *view_;
public:
cursor() = default;
explicit cursor(generate_view &view)
: view_(&view)
{}
result_t read() const
{
return view_->val_;
}
void next()
{
view_->next();
}
};
void next()
{
val_ = invoke(gen_);
}
cursor begin_cursor()
{
return cursor{*this};
}
unreachable end_cursor() const
{
return {};
}
public:
generate_view() = default;
explicit generate_view(G g)
: gen_(std::move(g)), val_(gen_())
{}
result_t & cached()
{
return val_;
}
};
namespace view
{
struct generate_fn
{
template<typename G>
using Concept = meta::and_<
Invocable<G&>,
MoveConstructible<G>,
std::is_object<detail::decay_t<result_of_t<G&()>>>,
Constructible<detail::decay_t<result_of_t<G&()>>, result_of_t<G&()>>,
Assignable<detail::decay_t<result_of_t<G&()>>&, result_of_t<G&()>>>;
template<typename G,
CONCEPT_REQUIRES_(Concept<G>())>
generate_view<G> operator()(G g) const
{
return generate_view<G>{std::move(g)};
}
#ifndef RANGES_DOXYGEN_INVOKED
template<typename G,
CONCEPT_REQUIRES_(!Concept<G>())>
void operator()(G) const
{
check<G>();
}
template<typename G>
static void check()
{
CONCEPT_ASSERT_MSG(Invocable<G&>(),
"The function object G must be callable with no arguments.");
CONCEPT_ASSERT_MSG(MoveConstructible<G>(),
"The function object G must be MoveConstructible.");
using T = result_of_t<G&()>;
using D = detail::decay_t<T>;
CONCEPT_ASSERT_MSG(std::is_object<D>(),
"The return type of the function object G must decay to an object type.");
CONCEPT_ASSERT_MSG(Constructible<D, T>(),
"The decayed return type of the function object G must be Constructible from the "
"return type of G.");
CONCEPT_ASSERT_MSG(Assignable<D&, T>(),
"The decayed return type of the function object G must be Assignable from the "
"return type of G.");
}
#endif
};
/// \relates generate_fn
/// \ingroup group-views
RANGES_INLINE_VARIABLE(generate_fn, generate)
}
/// \@}
}
}
RANGES_SATISFY_BOOST_RANGE(::ranges::v3::generate_view)
#endif
|