// 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_MAYBE_H namespace ircd { inline namespace util { using maybe_void_type = std::tuple; template using maybe_retval = typename std::invoke_result::type; template using maybe_type = std::tuple, std::exception_ptr>; template constexpr bool maybe_void(); template typename std::enable_if(), maybe_type>::type maybe(function&& f) noexcept try { return { f(), std::exception_ptr{} }; } catch(...) { return { {}, std::current_exception() }; } template typename std::enable_if(), maybe_void_type>::type maybe(function&& f) noexcept try { f(); return { true, std::exception_ptr{} }; } catch(...) { return { false, std::current_exception() }; } template constexpr bool maybe_void() { return std::is_same, void>(); } }}