MySQL 9.6.0
Source Code Documentation
mysql::utils Namespace Reference

Namespaces

namespace  detail
 
namespace  throwing
 

Classes

class  Error
 Error representation used internally in case final error code is unknown and error situation handling needs to be done by the caller. More...
 
struct  Tuple_count_helper
 Primary template for helper struct used to define Tuple_find_index. More...
 
struct  Tuple_count_helper< Tuple, Pred, index >
 Specialization of Tuple_count_helper to the case where index is in range. More...
 
struct  Tuple_find_helper
 Primary template for helper struct used to define Tuple_find_index. More...
 
struct  Tuple_find_helper< Tuple, Pred, index >
 Specialization of Tuple_find_helper to the case where the component at position index satisfies the predicate. More...
 

Concepts

concept  Is_enum
 true if Enum_t is an enumeration type (scoped or not).
 
concept  Tuple_has_matching_element_type
 True if at least one element type in the tuple-like type mathes the type predicate.
 
concept  Tuple_has_element_type
 True if the tuple has an element of the given type.
 

Typedefs

using Return_t = decltype(call_function())
 
using Error_ptr = std::unique_ptr< mysql::utils::Error >
 
template<class Tuple , template< class > class Pred>
using Tuple_find = Tuple_find_helper< Tuple, Pred >::type
 The first element type in the tuple-like type that matches the type predicate. More...
 

Enumerations

enum class  Return_status { ok , error }
 Simple, strongly-typed enumeration to indicate internal status: ok, error. More...
 

Functions

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_statusto_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...
 

Variables

template<class Function_t , class... Args_t>
 noexcept
 The return type for any call_and_catch(f, args...) call where f(args...) returns Type. More...
 
 else
 
template<class Tuple , template< class > class Pred>
constexpr std::size_t Tuple_find_index
 Index of the first element of the tuple-like type whose type matches the type predicate. More...
 
template<class Tuple , template< class > class Pred>
constexpr std::size_t Tuple_matching_element_type_count
 The number of tuple element types that match the given predicate. More...
 

Typedef Documentation

◆ Error_ptr

using mysql::utils::Error_ptr = typedef std::unique_ptr<mysql::utils::Error>

◆ Return_t

using mysql::utils::Return_t = typedef decltype(call_function())

◆ Tuple_find

template<class Tuple , template< class > class Pred>
using mysql::utils::Tuple_find = typedef Tuple_find_helper<Tuple, Pred>::type

The first element type in the tuple-like type that matches the type predicate.

This is undefined if no element type matches the predicate.

Template Parameters
TupleAny tuple-like object (https://en.cppreference.com/w/cpp/utility/tuple/tuple-like).
PredType predicate, i.e., a template class such that Pred<T>value is a truth value. This may, for example, be a UnaryTypeTrait (https://en.cppreference.com/w/cpp/named_req/UnaryTypeTrait.html)
// The first element type that satisfies is_integral is `short`.
static_assert(std::same_as<
short>);
Tuple_find_helper< Tuple, Pred >::type Tuple_find
The first element type in the tuple-like type that matches the type predicate.
Definition: tuple_find.h:132

Enumeration Type Documentation

◆ Return_status

enum class mysql::utils::Return_status
strong

Simple, strongly-typed enumeration to indicate internal status: ok, error.

Enumerator
ok 

operation succeeded

error 

operation failed

Function Documentation

◆ byte_cast()

template<class Type_t >
decltype(auto) mysql::utils::byte_cast ( Type_t &&  value)

Shorthand for char_cast<std::byte>.

◆ char_cast() [1/4]

template<mysql::meta::Is_charlike Char_t = char>
const Char_t & mysql::utils::char_cast ( const mysql::meta::Is_charlike auto &  ref)

◆ char_cast() [2/4]

template<mysql::meta::Is_charlike Char_t = char>
const Char_t * mysql::utils::char_cast ( const mysql::meta::Is_charlike auto *  ptr)

◆ char_cast() [3/4]

template<mysql::meta::Is_charlike Char_t = char>
Char_t & mysql::utils::char_cast ( mysql::meta::Is_charlike auto &  ref)

◆ char_cast() [4/4]

template<mysql::meta::Is_charlike Char_t = char>
Char_t * mysql::utils::char_cast ( mysql::meta::Is_charlike auto *  ptr)

◆ concat()

template<class... Args_t>
std::optional< std::string > mysql::utils::concat ( Args_t &&...  args)
noexcept

Stream all the arguments to a stringstream and return the resulting string.

Parameters
argsArguments to concatenate.
Returns
std::optional<std::string>, holding a value on success, or holding no value if an out-of-memory condition occurs.

◆ conditional_call_and_catch()

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

◆ enum_max()

template<Is_enum Enum_type>
constexpr Enum_type mysql::utils::enum_max ( )
constexpr

Template function that returns maximum valid constant that can appear in the enumeration type.

It must be specialized for each enumeration type serialized

Template Parameters
Enum_typeType of the enumeration that will be returned
Returns
Last valid enumeration constant within Enum_type

◆ enum_max< gtid::Gtid_format >()

template<>
constexpr gtid::Gtid_format mysql::utils::enum_max< gtid::Gtid_format > ( )
inlineconstexpr

Specialization of enum_max method for Gtid_format.

Returns
Maximum Gtid_format constant that can appear

◆ enum_max< mysql::strconv::Gtid_binary_format::Version >()

◆ forward_like()

template<class Qualifiers_from_t , class Value_t >
constexpr auto && mysql::utils::forward_like ( Value_t &&  x)
constexprnoexcept

Implementation of C++23's std::forward_like.

◆ if() [1/2]

constexpr mysql::utils::if ( noexcept(function(std::forward< Args_t >(args)...))  )
constexpr

◆ if() [2/2]

else constexpr mysql::utils::if ( std::same_as< Return_t, void >  )
constexpr

◆ is_same_object()

template<class Obj1_t , class Obj2_t >
bool mysql::utils::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.

◆ to_enumeration()

template<Is_enum Enum_type>
constexpr std::pair< Enum_type, Return_status > mysql::utils::to_enumeration ( std::integral auto  value)
constexpr

Helper function that converts value of enumeration underlying type into enumeration type constant.

Template Parameters
Enum_typeType of the enumeration that Integral_type parameter is converted into

◆ to_underlying()

template<Is_enum Enum_type>
constexpr decltype(auto) mysql::utils::to_underlying ( Enum_type  enum_value)
constexpr

Helper function that converts enum type to underlying integer type.

Note
This function may be removed after switching to C++23
Template Parameters
Enum_typeType of the enumeration parameter that gets converted into the underlying type value

◆ tuple_find()

template<template< class > class Pred, class Tuple >
auto mysql::utils::tuple_find ( const Tuple &  tuple)

Return the value of the first component of the tuple-like object whose type matches the given type predicate.

Template Parameters
TupleAny tuple-like object (https://en.cppreference.com/w/cpp/utility/tuple/tuple-like).
PredType predicate, i.e., a template class such that Pred<T>value is a truth value. This may, for example, be a UnaryTypeTrait (https://en.cppreference.com/w/cpp/named_req/UnaryTypeTrait.html)
// The first element whose type satisfies is_integral is the 9 (an int).
assert(tuple_find(std::is_integral, std::tuple("x", 2.1, 9)) == 9);
auto tuple_find(const Tuple &tuple)
Return the value of the first component of the tuple-like object whose type matches the given type pr...
Definition: tuple_find.h:175

◆ uchar_cast()

template<class Type_t >
decltype(auto) mysql::utils::uchar_cast ( Type_t &&  value)

Shorthand for char_cast<unsigned char>.

◆ void_to_ok()

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(/*args...*/) { this overload cannot fail }
[[nodiscard]] Return_status f(/*args...*/) { this overload can 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(/*args...*/) {
...
return w1(/*args...*/);
}
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:

[[nodiscard]] Return_status w2(/*args...*/) {
...
if (/*condition1*/) return Return_status::ok;
...
if (/*condition2*/) return Return_status::error;
...
if (/*condition3*/) return void_to_ok([&] { return f(/*args...*/); });
...
}
@ ok
operation succeeded
@ error
operation failed
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_tThe 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_tThe type of the function to call.
Args_tTypes of the arguments.
Parameters
funcFunction to call.
argsArguments 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.

Variable Documentation

◆ else

mysql::utils::else
Initial value:
{
try {
if constexpr (std::is_reference_v<Return_t>)
return std::make_optional(std::ref(call_function()));
else
return std::make_optional(call_function());
} catch (...) {
return Call_and_catch_type<Return_t>();
}
}
}
enum class Shall_catch { no, yes }
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359

◆ noexcept

template<class Function_t , class... Args_t>
mysql::utils::noexcept
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
functionAny function, possibly throwing.
argsParameters 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.

◆ Tuple_find_index

template<class Tuple , template< class > class Pred>
constexpr std::size_t mysql::utils::Tuple_find_index
constexpr
Initial value:
=
Primary template for helper struct used to define Tuple_find_index.
Definition: tuple_find.h:43

Index of the first element of the tuple-like type whose type matches the type predicate.

This is undefined if no element type matches the predicate.

Template Parameters
TupleAny tuple-like object (https://en.cppreference.com/w/cpp/utility/tuple/tuple-like).
PredType predicate, i.e., a template class such that Pred<T>value is a truth value. This may, for example, be a UnaryTypeTrait (https://en.cppreference.com/w/cpp/named_req/UnaryTypeTrait.html)
// The first element type that satisfies is_integral is `int` at index 1.
static_assert(
Tuple_find_index<std::is_integral, std::tuple<float, int>> == 1);

◆ Tuple_matching_element_type_count

template<class Tuple , template< class > class Pred>
constexpr std::size_t mysql::utils::Tuple_matching_element_type_count
constexpr
Initial value:
=
Primary template for helper struct used to define Tuple_find_index.
Definition: tuple_find.h:66

The number of tuple element types that match the given predicate.

Template Parameters
TupleAny tuple-like object (https://en.cppreference.com/w/cpp/utility/tuple/tuple-like).
PredType predicate, i.e., a template class such that Pred<T>value is a truth value. This may, for example, be a UnaryTypeTrait (https://en.cppreference.com/w/cpp/named_req/UnaryTypeTrait.html)