/usr/include/bobcat/fnwrap is in libbobcat-dev 2.20.01-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 | #ifndef INCLUDED_BOBCAT_FNWRAP_
#define INCLUDED_BOBCAT_FNWRAP_
#include <tuple>
#include <bobcat/typetrait>
namespace FBB
{
class FnWrap
{
template <typename Function>
struct Dissect
{};
template <typename Ret, typename ...Args>
struct Dissect <Ret (*)(Args ...)>
{
typedef Ret ReturnType;
};
typedef Dissect<int> *NotUsed;
template <size_t count, typename Tuple>
struct At
{
typedef typename std::tuple_element<count - 1, Tuple>::type Type;
};
template <typename RetType, typename Func, typename Arg1, typename Arg2,
size_t size, typename Tuple, typename ... Args>
struct CallPack: public CallPack<RetType, Arg1, Arg2, Func, size - 1,
Tuple, typename At<size, Tuple>::Type, Args ...>
{
typedef typename TypeTrait<Arg1>::Plain first_argument_type;
typedef typename TypeTrait<Arg2>::Plain second_argument_type;
typedef typename At<size, Tuple>::Type LastType;
static RetType call(Func fun, Arg1 &&arg1, Arg2 &&arg2,
Tuple &tuple, Args &&...args);
};
// specialization: unary + ret. type
template <typename RetType, typename Func, typename Arg1,
typename Tuple, typename ... Args>
struct CallPack<RetType, Func, Arg1, NotUsed, 0, Tuple, Args...>
{
static RetType call(Func fun, Arg1 &&arg1, NotUsed &&arg2,
Tuple &tuple, Args &&...args);
};
// specialization: binary + ret. type
template <typename RetType, typename Func, typename Arg1, typename Arg2,
typename Tuple, typename ... Args>
struct CallPack<RetType, Func, Arg1, Arg2, 0, Tuple, Args...>
{
static RetType call(Func fun, Arg1 &&arg1, Arg2 &&arg2,
Tuple &tuple, Args &&...args);
};
// specialization: void unary
template <typename Func, typename Arg1, typename Tuple, typename ... Args>
struct CallPack<void, Func, Arg1, NotUsed, 0, Tuple, Args...>
{
static void call(Func fun, Arg1 &&arg1, NotUsed &&arg2,
Tuple &tuple, Args &&...args);
};
// specialization: void binary
template <typename Func, typename Arg1, typename Arg2, typename Tuple,
typename ... Args>
struct CallPack<void, Func, Arg1, Arg2, 0, Tuple, Args...>
{
static void call(Func fun, Arg1 &&arg1, Arg2 &&arg2,
Tuple &tuple, Args &&...args);
};
public:
template <typename Function, typename ... Args>
struct Functor
{
typedef typename Dissect<Function>::ReturnType RetType;
Function d_function;
std::tuple<Args ...> d_args;
Functor(Function fun, Args &&... args);
template <typename Arg1, typename Arg2>
typename Functor::RetType operator()(Arg1 &&arg1, Arg2 &&arg2);
template <typename Arg1>
typename Functor::RetType operator()(Arg1 &&arg1);
};
template <typename Function, typename ... Args>
static Functor<Function, Args...> unary(Function fun, Args &&...args);
template <typename Function, typename ... Args>
static Functor<Function, Args...> binary(Function fun, Args &&...args);
};
// Generic CallPack::call function, unpacking the tuple
template <typename RetType, typename Func, typename Arg1, typename Arg2,
size_t size, typename Tuple, typename ... Args>
RetType FnWrap::CallPack<RetType, Func, Arg1, Arg2, size, Tuple, Args...
>::call(Func fun, Arg1 &&arg1, Arg2 &&arg2, Tuple &tuple, Args &&...args)
{
return CallPack<RetType, Func, Arg1, Arg2, size - 1, Tuple,
LastType, Args ...
>::call(fun, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2),
tuple, std::forward<LastType>(std::get<size - 1>(tuple)),
std::forward<Args>(args) ...
);
}
// Unary void CallPack::call function
template <typename Func, typename Arg1, typename Tuple, typename ... Args>
void FnWrap::CallPack<void, Func, Arg1, FnWrap::NotUsed, 0, Tuple,
Args...>::call( Func fun, Arg1 &&arg1, FnWrap::NotUsed &&arg2,
Tuple &tuple, Args &&...args)
{
fun(std::forward<Arg1>(arg1), std::forward<Args>(args)...);
}
// Unary non-void CallPack::call function
template <typename RetType, typename Func,
typename Arg1, typename Tuple, typename ... Args>
RetType FnWrap::CallPack<RetType, Func, Arg1, FnWrap::NotUsed, 0, Tuple,
Args...>::call( Func fun, Arg1 &&arg1, FnWrap::NotUsed &&arg2,
Tuple &tuple, Args &&...args)
{
return fun(std::forward<Arg1>(arg1), std::forward<Args>(args)...);
}
// Binary void CallPack::call function
template <typename Func, typename Arg1, typename Arg2, typename Tuple,
typename ... Args>
void FnWrap::CallPack<void, Func, Arg1, Arg2, 0, Tuple, Args...>::call(
Func fun, Arg1 &&arg1, Arg2 &&arg2, Tuple &tuple, Args &&...args)
{
fun(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2),
std::forward<Args>(args)...);
}
// Binary non-void CallPack::call function
template <typename RetType, typename Func, typename Arg1, typename Arg2,
typename Tuple, typename ... Args>
RetType FnWrap::CallPack<RetType, Func, Arg1, Arg2, 0, Tuple, Args...>::call(
Func fun, Arg1 &&arg1, Arg2 &&arg2, Tuple &tuple, Args &&...args)
{
return fun(std::forward<Arg1>(arg1), std::forward<Arg1>(arg1),
std::forward<Args>(args)...);
}
// Functor's constructor
template <typename Function, typename ... Args>
FnWrap::Functor<Function, Args...>::Functor(Function fun, Args &&... args)
:
d_function(fun),
d_args(std::forward<Args>(args)...)
{}
template <typename Function, typename ... Args> // unary operator()
template <typename Arg1>
typename FnWrap::Functor<Function, Args...>::RetType FnWrap::Functor<
Function, Args...>::operator()(Arg1 &&arg1)
{
return CallPack<RetType, Function, Arg1, NotUsed, sizeof ... (Args),
std::tuple<Args ...>
>::call(d_function, std::forward<Arg1>(arg1), 0, d_args);
}
template <typename Function, typename ... Args> // binary operator()
template <typename Arg1, typename Arg2>
typename FnWrap::Functor<Function, Args...>::RetType FnWrap::Functor<
Function, Args...>::operator()(Arg1 &&arg1, Arg2 &&arg2)
{
return CallPack<RetType, Function, Arg1, Arg2, sizeof ... (Args),
std::tuple<Args ...>
>::call(d_function,
std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), d_args);
}
template <typename Function, typename ... Args>
FnWrap::Functor<Function, Args...> context(Function fun, Args &&...args)
{
return FnWrap::Functor<Function, Args...>
(fun, std::forward<Args>(args) ...);
}
template <typename Function, typename ... Args>
FnWrap::Functor<Function, Args...> FnWrap::unary(Function fun, Args &&...args)
{
return Functor<Function, Args...>(fun, std::forward<Args>(args) ...);
}
template <typename Function, typename ... Args>
FnWrap::Functor<Function, Args...> FnWrap::binary(Function fun, Args &&...args)
{
return Functor<Function, Args...>(fun, std::forward<Args>(args) ...);
}
} // FBB
#endif
|