diff --git a/include/ircd/globular.h b/include/ircd/globular.h index e0335cb95..8fc86147e 100644 --- a/include/ircd/globular.h +++ b/include/ircd/globular.h @@ -22,7 +22,7 @@ namespace ircd /// and '?' characters and equality of the string expressions will be /// determined. Case insensitive. struct ircd::globular_iequals -:boolean +:returns { using is_transparent = std::true_type; @@ -31,7 +31,7 @@ struct ircd::globular_iequals template globular_iequals(A&& a, B&& b) - :boolean{operator()(std::forward(a), std::forward(b))} + :returns(operator()(std::forward(a), std::forward(b))) {} }; diff --git a/include/ircd/m/event/append.h b/include/ircd/m/event/append.h index cc8157293..e1f20ffad 100644 --- a/include/ircd/m/event/append.h +++ b/include/ircd/m/event/append.h @@ -25,7 +25,7 @@ namespace ircd::m /// find and add the prev_state/prev_content for state events, etc. /// struct ircd::m::event::append -:boolean +:returns { struct opts; diff --git a/include/ircd/m/feds.h b/include/ircd/m/feds.h index b28f64146..5c62f760b 100644 --- a/include/ircd/m/feds.h +++ b/include/ircd/m/feds.h @@ -45,7 +45,7 @@ namespace ircd::m::feds /// the user can distinguish different requests in their options vector. /// struct ircd::m::feds::execute -:boolean +:returns { execute(const vector_view &, const closure &); execute(const opts &, const closure &); diff --git a/include/ircd/m/push.h b/include/ircd/m/push.h index 01b569d80..016416518 100644 --- a/include/ircd/m/push.h +++ b/include/ircd/m/push.h @@ -59,7 +59,7 @@ decltype(ircd::m::push::request::list) ircd::instance_list::list; struct ircd::m::push::match -:boolean +:returns { struct opts; using cond_kind_func = bool (*)(const event &, const cond &, const opts &); diff --git a/include/ircd/m/redacted.h b/include/ircd/m/redacted.h index 444c641a8..3edff625f 100644 --- a/include/ircd/m/redacted.h +++ b/include/ircd/m/redacted.h @@ -17,7 +17,7 @@ namespace ircd::m } struct ircd::m::redacted -:boolean +:returns { redacted(const event::idx &); redacted(const event::id &); @@ -44,7 +44,7 @@ ircd::m::redacted::redacted(const event::id &event_id) inline ircd::m::redacted::redacted(const event::idx &event_idx) -:boolean +:returns { event_idx? event::refs(event_idx).has(dbs::ref::M_ROOM_REDACTION): diff --git a/include/ircd/m/room/power.h b/include/ircd/m/room/power.h index c1923ce1a..2596ae4cd 100644 --- a/include/ircd/m/room/power.h +++ b/include/ircd/m/room/power.h @@ -110,14 +110,14 @@ struct ircd::m::room::power }; struct ircd::m::room::power::grant -:boolean +:returns { grant(json::stack::object &, const room::power &, const pair &, const int64_t &); grant(json::stack::object &, const room::power &, const m::id::user &, const int64_t &); }; struct ircd::m::room::power::revoke -:boolean +:returns { revoke(json::stack::object &, const room::power &, const pair &); revoke(json::stack::object &, const room::power &, const m::id::user &); diff --git a/include/ircd/util/boolean.h b/include/ircd/util/boolean.h deleted file mode 100644 index 6de907726..000000000 --- a/include/ircd/util/boolean.h +++ /dev/null @@ -1,45 +0,0 @@ -// 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_BOOLEAN_H - -namespace ircd -{ - inline namespace util - { - struct boolean; - } -} - -/// Simple convenience for cheesers to inherit from a POD boolean, similar to -/// IRCD_STRONG_TYPEDEF(bool, boolean) but with additional specific features. -struct ircd::util::boolean -{ - bool val; - - operator const bool &() const noexcept - { - return val; - } - - explicit operator bool &() & noexcept - { - return val; - } - - boolean(const bool &val) noexcept - :val{val} - {} - - boolean(const std::function &func) - :val{func()} - {} -}; diff --git a/include/ircd/util/returns.h b/include/ircd/util/returns.h new file mode 100644 index 000000000..e95aa45a8 --- /dev/null +++ b/include/ircd/util/returns.h @@ -0,0 +1,49 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2023 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_RETURNS_H + +namespace ircd +{ + inline namespace util + { + template + struct returns; + } +} + +/// Simple convenience for cheesers to inherit from a POD type, similar to +/// IRCD_STRONG_TYPEDEF but with additional specific features. +template +struct ircd::util::returns +{ + T ret; + + operator const T &() const noexcept + { + return ret; + } + + explicit operator T &() & noexcept + { + return ret; + } + + returns(const std::function &func) + :ret{func()} + {} + + returns(const T &ret) noexcept + :ret{ret} + {} + + returns() = default; +}; diff --git a/include/ircd/util/util.h b/include/ircd/util/util.h index b2dc675a8..633c2bdd3 100644 --- a/include/ircd/util/util.h +++ b/include/ircd/util/util.h @@ -62,7 +62,7 @@ namespace ircd #include "closure.h" #include "env.h" #include "test.h" -#include "boolean.h" +#include "returns.h" #include "maybe.h" #include "all.h" #include "compare_exchange.h" diff --git a/matrix/event_append.cc b/matrix/event_append.cc index 2cc4cb409..5afb55c6d 100644 --- a/matrix/event_append.cc +++ b/matrix/event_append.cc @@ -54,7 +54,7 @@ ircd::m::event_append_default_keys ircd::m::event::append::append(json::stack::array &array, const event &event_, const opts &opts) -:boolean{[&] +:returns{[&] { assert(array.s); json::stack::checkpoint cp @@ -84,7 +84,7 @@ ircd::m::event::append::append(json::stack::array &array, ircd::m::event::append::append(json::stack::object &object, const event &event, const opts &opts) -:boolean{[&] +:returns{[&] { // Assertions that the event being appended has some required fields. This // is a central butt-end test of data coming through the system to here. diff --git a/matrix/feds.cc b/matrix/feds.cc index 0dcc93c62..e31c97b78 100644 --- a/matrix/feds.cc +++ b/matrix/feds.cc @@ -93,7 +93,7 @@ noexcept ircd::m::feds::execute::execute(const vector_view &optsv, const closure &closure) -:boolean{true} +:returns{true} { request_list list; for(const auto &opts : optsv) switch(opts.op) @@ -138,7 +138,7 @@ ircd::m::feds::execute::execute(const vector_view &optsv, for(const auto &opts : optsv) timeout = std::max(opts.timeout, timeout); - this->boolean::val = handler(list, timeout, closure); + ret = handler(list, timeout, closure); } ircd::m::feds::request_list diff --git a/matrix/push.cc b/matrix/push.cc index 4a5b3c8c6..bff63b6f7 100644 --- a/matrix/push.cc +++ b/matrix/push.cc @@ -110,7 +110,7 @@ ircd::m::push::match::cond_kind_name ircd::m::push::match::match(const event &event, const rule &rule, const match::opts &opts) -:boolean{[&event, &rule, &opts] +:returns{[&event, &rule, &opts] { if(json::get<"pattern"_>(rule)) { @@ -137,7 +137,7 @@ ircd::m::push::match::match(const event &event, ircd::m::push::match::match(const event &event, const cond &cond, const match::opts &opts) -:boolean{[&event, &cond, &opts] +:returns{[&event, &cond, &opts] { const string_view &kind { diff --git a/matrix/room_power.cc b/matrix/room_power.cc index 20a3f5603..939cf6487 100644 --- a/matrix/room_power.cc +++ b/matrix/room_power.cc @@ -11,7 +11,7 @@ ircd::m::room::power::revoke::revoke(json::stack::object &out, const room::power &power, const pair &prop_key) -:boolean{false} +:returns{false} { bool &ret(*this); const auto replace{[&ret] @@ -71,7 +71,7 @@ ircd::m::room::power::grant::grant(json::stack::object &out, const room::power &power, const pair &prop_key, const int64_t &level) -:boolean{false} +:returns{false} { bool &ret(*this); const auto replace{[&ret, &level]