18 #ifndef COMMON_FUNCTION_VIEW_H 19 #define COMMON_FUNCTION_VIEW_H 156 namespace fv_detail {
176 template<
class Signature>
179 template<
typename Res,
typename... Args>
182 template<
typename From,
typename To>
185 std::is_same<From, To>,
186 std::is_convertible<From, To>>;
190 template<
typename Callable,
191 typename Res2 =
typename std::result_of<Callable &(Args...)>::type>
197 template <
typename Callable>
198 struct IsFunctionView
199 : std::is_same<function_view, typename std::decay<Callable>::type>
206 : m_erased_callable {},
211 function_view (
const function_view &) =
default;
212 function_view &operator= (
const function_view &) =
default;
219 typename = Requires<Not<IsFunctionView<Callable>>>,
220 typename = Requires<IsCompatibleCallable<Callable>>>
228 : m_erased_callable {},
242 constexpr
explicit operator bool () const noexcept
243 {
return m_invoker !=
nullptr; }
246 Res operator () (Args... args)
const 247 {
return m_invoker (m_erased_callable, std::forward<Args> (args)...); }
253 template <
typename Callable>
254 void bind (Callable &callable) noexcept
256 m_erased_callable.data = (
void *) std::addressof (callable);
258 noexcept (noexcept (callable (std::forward<Args> (args)...))) -> Res
260 auto &restored_callable = *
static_cast<Callable *
> (ecall.
data);
263 return (Res) restored_callable (std::forward<Args> (args)...);
274 template<
class Res2,
typename... Args2>
275 void bind (Res2 (*fn) (Args2...)) noexcept
277 m_erased_callable.fn =
reinterpret_cast<void (*) ()
> (fn);
279 noexcept (noexcept (fn (std::forward<Args> (args)...))) -> Res
281 auto restored_fn =
reinterpret_cast<Res2 (*) (Args2...)
> (ecall.
fn);
284 return (Res) restored_fn (std::forward<Args> (args)...);
301 template<
typename Res,
typename... Args>
302 constexpr
inline bool 304 {
return !
static_cast<bool> (f); }
306 template<
typename Res,
typename... Args>
307 constexpr
inline bool 309 {
return !
static_cast<bool> (f); }
311 template<
typename Res,
typename... Args>
312 constexpr
inline bool 314 {
return static_cast<bool> (f); }
316 template<
typename Res,
typename... Args>
317 constexpr
inline bool 319 {
return static_cast<bool> (f); }
constexpr bool operator==(const function_view< Res(Args...)> &f, std::nullptr_t) noexcept
constexpr bool operator!=(const function_view< Res(Args...)> &f, std::nullptr_t) noexcept
void bind(Res2(*fn)(Args2...)) noexcept
function_view(Callable &&callable) noexcept
constexpr function_view() noexcept
constexpr function_view(std::nullptr_t) noexcept
void bind(Callable &callable) noexcept
fv_detail::erased_callable m_erased_callable