|
| template<> |
| constexpr gtid::Gtid_format | enum_max< gtid::Gtid_format > () |
| | Specialization of enum_max method for Gtid_format. More...
|
| |
| template<> |
| constexpr mysql::strconv::Gtid_binary_format::Version | enum_max< mysql::strconv::Gtid_binary_format::Version > () |
| |
| constexpr | if (noexcept(function(std::forward< Args_t >(args)...))) |
| |
| else constexpr | if (std::same_as< Return_t, void >) |
| |
| template<Shall_catch shall_catch, class Function_t , class... Args_t> |
| decltype(auto) | conditional_call_and_catch (const Function_t &function, Args_t &&...args) noexcept(noexcept(function(std::forward< Args_t >(args)...))||shall_catch==Shall_catch::yes) |
| | Call function, and if shall_catch is true, catch exceptions and wrap them in the return value. More...
|
| |
| template<mysql::meta::Is_charlike Char_t = char> |
| Char_t & | char_cast (mysql::meta::Is_charlike auto &ref) |
| |
| template<mysql::meta::Is_charlike Char_t = char> |
| const Char_t & | char_cast (const mysql::meta::Is_charlike auto &ref) |
| |
| template<mysql::meta::Is_charlike Char_t = char> |
| Char_t * | char_cast (mysql::meta::Is_charlike auto *ptr) |
| |
| template<mysql::meta::Is_charlike Char_t = char> |
| const Char_t * | char_cast (const mysql::meta::Is_charlike auto *ptr) |
| |
| template<class Type_t > |
| decltype(auto) | uchar_cast (Type_t &&value) |
| | Shorthand for char_cast<unsigned char>. More...
|
| |
| template<class Type_t > |
| decltype(auto) | byte_cast (Type_t &&value) |
| | Shorthand for char_cast<std::byte>. More...
|
| |
| template<class... Args_t> |
| std::optional< std::string > | concat (Args_t &&...args) noexcept |
| | Stream all the arguments to a stringstream and return the resulting string. More...
|
| |
| template<Is_enum Enum_type> |
| constexpr decltype(auto) | to_underlying (Enum_type enum_value) |
| | Helper function that converts enum type to underlying integer type. More...
|
| |
| template<Is_enum Enum_type> |
| constexpr Enum_type | enum_max () |
| | Template function that returns maximum valid constant that can appear in the enumeration type. More...
|
| |
| template<Is_enum Enum_type> |
| constexpr std::pair< Enum_type, Return_status > | to_enumeration (std::integral auto value) |
| | Helper function that converts value of enumeration underlying type into enumeration type constant. More...
|
| |
| template<class Qualifiers_from_t , class Value_t > |
| constexpr auto && | forward_like (Value_t &&x) noexcept |
| | Implementation of C++23's std::forward_like. More...
|
| |
| template<class Obj1_t , class Obj2_t > |
| bool | is_same_object (const Obj1_t &obj1, const Obj2_t &obj2) |
| | Return true if the types of the two objects are either equal or one derived from the other, and in addition, refer to the same object. More...
|
| |
template<class Return_t = Return_status, class Func_t , class... Args_t>
requires std::invocable<Func_t, Args_t...> |
| Return_t | void_to_ok (const Func_t &func, Args_t &&...args) |
| | Helper that calls the given function and returns its result, or returns Return_status::ok if the function returns void. More...
|
| |
| template<template< class > class Pred, class Tuple > |
| auto | tuple_find (const Tuple &tuple) |
| | Return the value of the first component of the tuple-like object whose type matches the given type predicate. More...
|
| |
template<Shall_catch shall_catch, class Function_t , class... Args_t>
| decltype(auto) mysql::utils::conditional_call_and_catch |
( |
const Function_t & |
function, |
|
|
Args_t &&... |
args |
|
) |
| |
|
noexcept |
Call function, and if shall_catch is true, catch exceptions and wrap them in the return value.
Otherwise, just call the function and return what the function returns.
- See also
- call_and_catch
template<class
Return_t = Return_status, class Func_t , class... Args_t>
requires std::invocable<Func_t, Args_t...>
| Return_t mysql::utils::void_to_ok |
( |
const Func_t & |
func, |
|
|
Args_t &&... |
args |
|
) |
| |
Helper that calls the given function and returns its result, or returns Return_status::ok if the function returns void.
Use case: Suppose a function f has two overloads: one that can fail and one that cannot fail. Then the overload that can fail should return Return_status and have the [[nodiscard]] attribute and the overload that cannot fail should return void, as follows:
void f() { this overload cannot fail }
@code
Then, a function template `w1` that invokes `f` and forwards the
return status (`w1` is a
"wrapper"), can be defined like:
@code
[[nodiscard]] auto w1() {
...
return w1();
}
Return_status
Simple, strongly-typed enumeration to indicate internal status: ok, error.
Definition: return_status.h:40
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
This makes w1 inherit both the return type and the [[nodiscard]] attribute from the overload of f that it invokes, since [[nodiscard]] is automatically dropped when the return type is deduced to void.
(If the non-failing overload of f would return Return_status::ok always, w1 would return Return_status::ok always, and have the [[nodiscard]] attribute always, which could force callers to check the return value even in cases it is known to always be ok).
Now, void_to_ok is usable in cases where a function template w2 needs to invoke f and forward the return status, and must always return Return_status, perhaps because w2 has error cases that do not depend on errors in the invocation of f. For example:
...
...
...
...
}
Return_t void_to_ok(const Func_t &func, Args_t &&...args)
Helper that calls the given function and returns its result, or returns Return_status::ok if the func...
Definition: return_status.h:113
- Template Parameters
-
| Return_t | The return type of this function. If Func_t returns non-void, Func_t's return type must be convertible to Return_t. The default is Return_status. |
| Func_t | The type of the function to call. |
| Args_t | Types of the arguments. |
- Parameters
-
| func | Function to call. |
| args | Arguments that will be forwarded to the function. |
- Returns
- Return_t: if
func returns non-void, casts the result to Return_t and returns it; otherwise returns a default-constructed Return_t value.
template<class Function_t , class... Args_t>
Initial value:{
auto call_function = [&]() -> decltype(auto) {
return function(std::forward<Args_t>(args)...);
}
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Calls a function, catches exceptions from it, and wraps the exception status in the return value.
- Parameters
-
| function | Any function, possibly throwing. |
| args | Parameters passed to the function. |
- Returns
- If
function is declared noexcept, this is equivalent to calling function directly and returning the result. Otherwise, if function returns void, this function returns mysql::utils::Return_status: error indicates out-of-memory and ok indicates success. Otherwise, if function returns a non-reference type, say T, this function returns std::optional<T>, which stores the return value on success, and uses no value on out-of-memory. Otherwise, function returns a reference type, say T &, this function returns std::optional<std::reference_wrapper<T>>, which holds a wrapper around the returned reference on success, and holds no value on error.