MySQL 9.6.0
Source Code Documentation
call_and_catch.h File Reference

Experimental API header. More...

#include <concepts>
#include <functional>
#include <optional>
#include <type_traits>
#include "mysql/utils/return_status.h"

Go to the source code of this file.

Namespaces

namespace  mysql
 
namespace  mysql::utils
 

Macros

#define DEDUCED_NOEXCEPT_FUNCTION(X)    noexcept(noexcept(X)) { return (X); }
 Helper macro to define a function that returns the result of a single expression, and has a conditional noexcept clause deduced from whether that expression is noexcept or not. More...
 

Typedefs

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

Functions

constexpr mysql::utils::if (noexcept(function(std::forward< Args_t >(args)...)))
 
else constexpr mysql::utils::if (std::same_as< Return_t, void >)
 
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(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...
 

Variables

template<class Function_t , class... Args_t>
 mysql::utils::noexcept
 The return type for any call_and_catch(f, args...) call where f(args...) returns Type. More...
 
 mysql::utils::else
 

Detailed Description

Experimental API header.

Macro Definition Documentation

◆ DEDUCED_NOEXCEPT_FUNCTION

#define DEDUCED_NOEXCEPT_FUNCTION (   X)     noexcept(noexcept(X)) { return (X); }

Helper macro to define a function that returns the result of a single expression, and has a conditional noexcept clause deduced from whether that expression is noexcept or not.

This expands to noexcept(noexcept(X)) { return (X); }.

class C { /*...*/ };
// for rvalue reference C, f never throws
void f(C &&) noexcept {}
// for const lvalue reference C, f may throw (maybe it needs to allocate)
void f(const C &) {}
// Call f(t). If f(t) may throw, catch any exceptions and return
// Call_and_catch_type<decltype(f(t))>. If f(t) is noexcept, just return
// what f(t) returned.
template <class T>
auto wrap_f(T &&t) {
return call_and_catch(
[&]() DEDUCED_NOEXCEPT_FUNCTION(f(std::forward<T>(t))));
}
#define DEDUCED_NOEXCEPT_FUNCTION(X)
Helper macro to define a function that returns the result of a single expression, and has a condition...
Definition: call_and_catch.h:151
#define T
Definition: jit_executor_value.cc:373
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76

See also Boost's BOOST_HOF_RETURNS.