/usr/include/range/v3/utility/dangling.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 | /// \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_UTILITY_DANGLING_HPP
#define RANGES_V3_UTILITY_DANGLING_HPP
#include <utility>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/tagged_pair.hpp>
#ifndef RANGES_NO_STD_FORWARD_DECLARATIONS
// Non-portable forward declarations of standard containers
RANGES_BEGIN_NAMESPACE_STD
template<typename...Ts>
class tuple;
RANGES_END_NAMESPACE_STD
#else
#include <tuple>
#endif
namespace ranges
{
inline namespace v3
{
/// \cond
namespace detail
{
template<typename T>
struct is_dangling
: meta::is<T, dangling>
{};
template<typename T>
struct is_dangling<T &>
: is_dangling<T>
{};
template<typename T>
struct is_dangling<T const>
: is_dangling<T>
{};
}
/// \endcond
struct sanitize_fn;
/// \ingroup group-core
/// A wrapper for an iterator or a sentinel into a range that may
/// no longer be valid.
template<typename I>
struct dangling
{
private:
I it_;
public:
dangling() = default;
/// Implicit converting constructor
constexpr dangling(I it)
: it_(it)
{}
/// \return The iterator from which this \c dangling object was constructed.
/// \note The returned iterator may be invalid.
/// \pre
/// \li Either the range from which the iterator was obtained has not been
/// destructed yet, or else the range's iterators are permitted to outlive the
/// range, and
/// \li No operation that invalidates the iterator has been performed.
constexpr I get_unsafe() const
{
return it_;
}
};
template<>
struct dangling<void>
{
private:
friend struct sanitize_fn;
template<typename T>
dangling(dangling<T> const &)
{}
public:
dangling() = default;
};
/// \ingroup group-core
struct sanitize_fn
{
private:
template<typename T>
using result_t = decltype(std::declval<sanitize_fn const &>()(std::declval<T>()));
template<typename Res, typename Tuple, typename ...Ts, std::size_t...Is>
constexpr Res sanitize_tuple(Tuple &&tup,
meta::list<Ts...>, meta::index_sequence<Is...>) const
{
return Res{
(*this)(static_cast<Ts &&>(std::get<Is>(static_cast<Tuple &&>(tup))))...};
}
public:
template<typename T>
constexpr meta::if_<detail::is_dangling<T>, dangling<>, T> operator()(T &&t) const
{
return static_cast<T&&>(t);
}
template<typename T, typename U>
constexpr std::pair<result_t<T>, result_t<U>> operator()(std::pair<T, U> &p) const
{
return {(*this)(p.first), (*this)(p.second)};
}
template<typename T, typename U>
constexpr std::pair<result_t<T>, result_t<U>> operator()(std::pair<T, U> const &p) const
{
return {(*this)(p.first), (*this)(p.second)};
}
template<typename T, typename U>
constexpr std::pair<result_t<T>, result_t<U>> operator()(std::pair<T, U> &&p) const
{
return {(*this)(static_cast<T &&>(p.first)), (*this)(static_cast<U &&>(p.second))};
}
template<typename ...Ts>
constexpr std::tuple<result_t<Ts>...> operator()(std::tuple<Ts...> &tup) const
{
return this->sanitize_tuple<std::tuple<result_t<Ts>...>>(tup,
meta::list<Ts &...>{}, meta::make_index_sequence<sizeof...(Ts)>{});
}
template<typename ...Ts>
constexpr std::tuple<result_t<Ts>...> operator()(std::tuple<Ts...> const &tup) const
{
return this->sanitize_tuple<std::tuple<result_t<Ts>...>>(tup,
meta::list<Ts const &...>{}, meta::make_index_sequence<sizeof...(Ts)>{});
}
template<typename ...Ts>
constexpr std::tuple<result_t<Ts>...> operator()(std::tuple<Ts...> &&tup) const
{
return this->sanitize_tuple<std::tuple<result_t<Ts>...>>(std::move(tup),
meta::list<Ts...>{}, meta::make_index_sequence<sizeof...(Ts)>{});
}
template<typename Base, typename... Tags>
constexpr tagged<result_t<Base &>, Tags...> operator()(tagged<Base, Tags...> &tup) const
{
return (*this)(static_cast<Base &>(tup));
}
template<typename Base, typename... Tags>
constexpr tagged<result_t<Base const &>, Tags...> operator()(tagged<Base, Tags...> const &tup) const
{
return (*this)(static_cast<Base const &>(tup));
}
template<typename Base, typename... Tags>
constexpr tagged<result_t<Base &&>, Tags...> operator()(tagged<Base, Tags...> &&tup) const
{
return (*this)(static_cast<Base &&>(tup));
}
};
/// \ingroup group-core
struct get_unsafe_fn
{
/// \return \c t.get_unsafe() if \p t is an instance of `ranges::dangling`; otherwise,
/// return \p t.
template<typename T>
constexpr T operator()(T && t) const
{
return static_cast<T&&>(t);
}
/// \overload
template<typename T>
constexpr T operator()(dangling<T> t) const
{
return t.get_unsafe();
}
};
/// \ingroup group-core
/// \return \c t.get_unsafe() if \p t is an instance of `ranges::dangling`; otherwise,
/// return \p t.
RANGES_INLINE_VARIABLE(get_unsafe_fn, get_unsafe)
/// \ingroup group-core
/// \return the result of replacing all \c ranges::dangling<T> objects with
/// \c ranges::dangling<void>, introspecting \c std::pair and \c std::tuple
/// objects recursively.
RANGES_INLINE_VARIABLE(sanitize_fn, sanitize)
}
}
#endif
|