// Matrix Construct // // Copyright (C) Matrix Construct Developers, Authors & Contributors // Copyright (C) 2016-2019 Jason Volk // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. #pragma once #define HAVE_IRCD_UTIL_CLOSURE_H namespace ircd { inline namespace util { template class F, class R, class... A> struct closure; template class F, class... A> struct closure; /// Template for creating callback-based iterations allowing closures of /// either `void (...)` or `bool (...)` to be passed to the same overload. /// /// This reduces/deduplicates interfaces which offer an overload for each /// and thus two library symbols, usually just calling each other... /// template class F, class... A> using closure_bool = closure; }} template class F, class R, class... A> struct ircd::util::closure :F { using proto_type = R (A...); using func_type = F; using func_type::func_type; using func_type::operator=; }; template class F, class... A> struct ircd::util::closure :F { using proto_bool_type = bool (A...); using proto_void_type = void (A...); using func_bool_type = F; using func_void_type = F; template closure(lambda &&o, typename std::enable_if::value, int>::type = 0) noexcept; template closure(lambda &&o, typename std::enable_if::value, int>::type = 0) noexcept; }; template class F, class... A> template [[gnu::always_inline]] inline ircd::util::closure::closure(lambda &&o, typename std::enable_if::value, int>::type) noexcept :F { [o(std::move(o))](A&&... a) { static_assert ( std::is_same(a)...))>() ); o(std::forward(a)...); return true; } } {} template class F, class... A> template [[gnu::always_inline]] inline ircd::util::closure::closure(lambda &&o, typename std::enable_if::value, int>::type) noexcept :F { std::forward(o) } {}