/usr/include/boost/hana/lazy.hpp is in libboost1.65-dev 1.65.1+dfsg-0ubuntu5.
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 | /*!
@file
Defines `boost::hana::lazy`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_LAZY_HPP
#define BOOST_HANA_LAZY_HPP
#include <boost/hana/fwd/lazy.hpp>
#include <boost/hana/basic_tuple.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/core/make.hpp>
#include <boost/hana/detail/decay.hpp>
#include <boost/hana/detail/operators/adl.hpp>
#include <boost/hana/detail/operators/monad.hpp>
#include <boost/hana/functional/apply.hpp>
#include <boost/hana/functional/compose.hpp>
#include <boost/hana/functional/on.hpp>
#include <boost/hana/fwd/ap.hpp>
#include <boost/hana/fwd/duplicate.hpp>
#include <boost/hana/fwd/eval.hpp>
#include <boost/hana/fwd/extend.hpp>
#include <boost/hana/fwd/extract.hpp>
#include <boost/hana/fwd/flatten.hpp>
#include <boost/hana/fwd/lift.hpp>
#include <boost/hana/fwd/transform.hpp>
#include <cstddef>
#include <type_traits>
#include <utility>
BOOST_HANA_NAMESPACE_BEGIN
//////////////////////////////////////////////////////////////////////////
// lazy
//////////////////////////////////////////////////////////////////////////
template <typename Indices, typename F, typename ...Args>
struct lazy_apply_t;
namespace detail { struct lazy_secret { }; }
template <std::size_t ...n, typename F, typename ...Args>
struct lazy_apply_t<std::index_sequence<n...>, F, Args...>
: detail::operators::adl<>
{
template <typename ...T>
constexpr lazy_apply_t(detail::lazy_secret, T&& ...t)
: storage_{static_cast<T&&>(t)...}
{ }
basic_tuple<F, Args...> storage_;
using hana_tag = lazy_tag;
};
template <typename X>
struct lazy_value_t : detail::operators::adl<> {
template <typename Y>
constexpr lazy_value_t(detail::lazy_secret, Y&& y)
: storage_{static_cast<Y&&>(y)}
{ }
basic_tuple<X> storage_;
using hana_tag = lazy_tag;
// If this is called, we assume that `X` is in fact a function.
template <typename ...Args>
constexpr lazy_apply_t<
std::make_index_sequence<sizeof...(Args)>,
X, typename detail::decay<Args>::type...
> operator()(Args&& ...args) const& {
return {detail::lazy_secret{},
hana::at_c<0>(storage_), static_cast<Args&&>(args)...};
}
template <typename ...Args>
constexpr lazy_apply_t<
std::make_index_sequence<sizeof...(Args)>,
X, typename detail::decay<Args>::type...
> operator()(Args&& ...args) && {
return {detail::lazy_secret{},
static_cast<X&&>(hana::at_c<0>(storage_)),
static_cast<Args&&>(args)...
};
}
};
//////////////////////////////////////////////////////////////////////////
// make<lazy_tag>
//////////////////////////////////////////////////////////////////////////
template <>
struct make_impl<lazy_tag> {
template <typename X>
static constexpr lazy_value_t<typename detail::decay<X>::type> apply(X&& x) {
return {detail::lazy_secret{}, static_cast<X&&>(x)};
}
};
//////////////////////////////////////////////////////////////////////////
// Operators
//////////////////////////////////////////////////////////////////////////
namespace detail {
template <>
struct monad_operators<lazy_tag> { static constexpr bool value = true; };
}
//////////////////////////////////////////////////////////////////////////
// eval for lazy_tag
//////////////////////////////////////////////////////////////////////////
template <>
struct eval_impl<lazy_tag> {
// lazy_apply_t
template <std::size_t ...n, typename F, typename ...Args>
static constexpr decltype(auto)
apply(lazy_apply_t<std::index_sequence<n...>, F, Args...> const& expr) {
return hana::at_c<0>(expr.storage_)(
hana::at_c<n+1>(expr.storage_)...
);
}
template <std::size_t ...n, typename F, typename ...Args>
static constexpr decltype(auto)
apply(lazy_apply_t<std::index_sequence<n...>, F, Args...>& expr) {
return hana::at_c<0>(expr.storage_)(
hana::at_c<n+1>(expr.storage_)...
);
}
template <std::size_t ...n, typename F, typename ...Args>
static constexpr decltype(auto)
apply(lazy_apply_t<std::index_sequence<n...>, F, Args...>&& expr) {
return static_cast<F&&>(hana::at_c<0>(expr.storage_))(
static_cast<Args&&>(hana::at_c<n+1>(expr.storage_))...
);
}
// lazy_value_t
template <typename X>
static constexpr X const& apply(lazy_value_t<X> const& expr)
{ return hana::at_c<0>(expr.storage_); }
template <typename X>
static constexpr X& apply(lazy_value_t<X>& expr)
{ return hana::at_c<0>(expr.storage_); }
template <typename X>
static constexpr X apply(lazy_value_t<X>&& expr)
{ return static_cast<X&&>(hana::at_c<0>(expr.storage_)); }
};
//////////////////////////////////////////////////////////////////////////
// Functor
//////////////////////////////////////////////////////////////////////////
template <>
struct transform_impl<lazy_tag> {
template <typename Expr, typename F>
static constexpr auto apply(Expr&& expr, F&& f) {
return hana::make_lazy(hana::compose(static_cast<F&&>(f), hana::eval))(
static_cast<Expr&&>(expr)
);
}
};
//////////////////////////////////////////////////////////////////////////
// Applicative
//////////////////////////////////////////////////////////////////////////
template <>
struct lift_impl<lazy_tag> {
template <typename X>
static constexpr lazy_value_t<typename detail::decay<X>::type>
apply(X&& x) {
return {detail::lazy_secret{}, static_cast<X&&>(x)};
}
};
template <>
struct ap_impl<lazy_tag> {
template <typename F, typename X>
static constexpr decltype(auto) apply(F&& f, X&& x) {
return hana::make_lazy(hana::on(hana::apply, hana::eval))(
static_cast<F&&>(f), static_cast<X&&>(x)
);
}
};
//////////////////////////////////////////////////////////////////////////
// Monad
//////////////////////////////////////////////////////////////////////////
template <>
struct flatten_impl<lazy_tag> {
template <typename Expr>
static constexpr decltype(auto) apply(Expr&& expr) {
return hana::make_lazy(hana::compose(hana::eval, hana::eval))(
static_cast<Expr&&>(expr)
);
}
};
//////////////////////////////////////////////////////////////////////////
// Comonad
//////////////////////////////////////////////////////////////////////////
template <>
struct extract_impl<lazy_tag> {
template <typename Expr>
static constexpr decltype(auto) apply(Expr&& expr)
{ return hana::eval(static_cast<Expr&&>(expr)); }
};
template <>
struct duplicate_impl<lazy_tag> {
template <typename Expr>
static constexpr decltype(auto) apply(Expr&& expr)
{ return hana::make_lazy(static_cast<Expr&&>(expr)); }
};
template <>
struct extend_impl<lazy_tag> {
template <typename Expr, typename F>
static constexpr decltype(auto) apply(Expr&& expr, F&& f) {
return hana::make_lazy(static_cast<F&&>(f))(static_cast<Expr&&>(expr));
}
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_LAZY_HPP
|