Skip to content

Commit

Permalink
C++11 support for deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
anarthal committed Dec 4, 2023
1 parent 378fa37 commit 6a43eeb
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 125 deletions.
178 changes: 63 additions & 115 deletions include/boost/mysql/any_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <boost/mysql/diagnostics.hpp>
#include <boost/mysql/error_code.hpp>
#include <boost/mysql/execution_state.hpp>
#include <boost/mysql/handshake_params.hpp>
#include <boost/mysql/metadata_mode.hpp>
#include <boost/mysql/results.hpp>
#include <boost/mysql/rows_view.hpp>
Expand Down Expand Up @@ -265,16 +266,16 @@ class any_connection
* The handler signature for this operation is `void(boost::mysql::error_code)`.
*/
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_connect(const connect_params& params, CompletionToken&& token)
auto async_connect(const connect_params& params, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_connect_t<detail::any_address_view, CompletionToken>)
{
return async_connect(params, impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_connect
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_connect(const connect_params& params, diagnostics& diag, CompletionToken&& token)
auto async_connect(const connect_params& params, diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_connect_t<detail::any_address_view, CompletionToken>)
{
auto stable_prms = detail::make_stable(params);
return impl_.async_connect(
Expand Down Expand Up @@ -303,8 +304,8 @@ class any_connection
* The handler signature for this operation is `void(boost::mysql::error_code)`.
*/
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_connect(const connect_params* params, diagnostics& diag, CompletionToken&& token)
auto async_connect(const connect_params* params, diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_connect_t<detail::any_address_view, CompletionToken>)
{
BOOST_ASSERT(params != nullptr);
return impl_.async_connect(
Expand Down Expand Up @@ -336,14 +337,9 @@ class any_connection
template <
BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
BOOST_MYSQL_RESULTS_TYPE ResultsType,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_execute(
ExecutionRequest&& req,
ResultsType& result,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_execute(ExecutionRequest&& req, ResultsType& result, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_execute_t<ExecutionRequest, ResultsType, CompletionToken>)
{
return async_execute(
std::forward<ExecutionRequest>(req),
Expand All @@ -357,15 +353,13 @@ class any_connection
template <
BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
BOOST_MYSQL_RESULTS_TYPE ResultsType,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_execute(
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_execute(
ExecutionRequest&& req,
ResultsType& result,
diagnostics& diag,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
CompletionToken&& token
) BOOST_MYSQL_RETURN_TYPE(detail::async_execute_t<ExecutionRequest, ResultsType, CompletionToken>)
{
return impl_.async_execute(
std::forward<ExecutionRequest>(req),
Expand Down Expand Up @@ -405,14 +399,12 @@ class any_connection
template <
BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_start_execution(
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_start_execution(
ExecutionRequest&& req,
ExecutionStateType& st,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
CompletionToken&& token
) BOOST_MYSQL_RETURN_TYPE(detail::async_execute_t<ExecutionRequest, ExecutionStateType, CompletionToken>)
{
return async_start_execution(
std::forward<ExecutionRequest>(req),
Expand All @@ -426,15 +418,13 @@ class any_connection
template <
BOOST_MYSQL_EXECUTION_REQUEST ExecutionRequest,
BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_start_execution(
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_start_execution(
ExecutionRequest&& req,
ExecutionStateType& st,
diagnostics& diag,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
CompletionToken&& token
) BOOST_MYSQL_RETURN_TYPE(detail::async_execute_t<ExecutionRequest, ExecutionStateType, CompletionToken>)
{
return impl_.async_start_execution(
std::forward<ExecutionRequest>(req),
Expand Down Expand Up @@ -462,25 +452,18 @@ class any_connection

/// \copydoc connection::async_prepare_statement
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::statement))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, statement))
async_prepare_statement(
string_view stmt,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
CompletionToken>
auto async_prepare_statement(string_view stmt, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_prepare_statement_t<CompletionToken>)
{
return async_prepare_statement(stmt, impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_prepare_statement
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::statement))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, statement))
async_prepare_statement(
string_view stmt,
diagnostics& diag,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
CompletionToken>
auto async_prepare_statement(string_view stmt, diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_prepare_statement_t<CompletionToken>)
{
return impl_.async_run(
detail::prepare_statement_algo_params{&diag, stmt},
Expand All @@ -504,26 +487,17 @@ class any_connection
}

/// \copydoc connection::async_close_statement
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_close_statement(
const statement& stmt,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_close_statement(const statement& stmt, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_close_statement_t<CompletionToken>)
{
return async_close_statement(stmt, impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_close_statement
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_close_statement(
const statement& stmt,
diagnostics& diag,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_close_statement(const statement& stmt, diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_close_statement_t<CompletionToken>)
{
return impl_.async_run(
impl_.make_params_close_statement(stmt, diag),
Expand All @@ -549,25 +523,18 @@ class any_connection

/// \copydoc connection::async_read_some_rows(execution_state&,CompletionToken&&)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::rows_view))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, rows_view))
async_read_some_rows(
execution_state& st,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
CompletionToken>
auto async_read_some_rows(execution_state& st, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_read_some_rows_dynamic_t<CompletionToken>)
{
return async_read_some_rows(st, impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_read_some_rows(execution_state&,CompletionToken&&)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, ::boost::mysql::rows_view))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, rows_view))
async_read_some_rows(
execution_state& st,
diagnostics& diag,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
CompletionToken>
auto async_read_some_rows(execution_state& st, diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_read_some_rows_dynamic_t<CompletionToken>)
{
return impl_.async_run(
impl_.make_params_read_some_rows(st, diag),
Expand Down Expand Up @@ -688,8 +655,7 @@ class any_connection
class... StaticRow,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, std::size_t))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, std::size_t))
async_read_some_rows(
auto async_read_some_rows(
static_execution_state<StaticRow...>& st,
span<SpanStaticRow> output,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
Expand Down Expand Up @@ -736,8 +702,7 @@ class any_connection
class... StaticRow,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code, std::size_t))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, std::size_t))
async_read_some_rows(
auto async_read_some_rows(
static_execution_state<StaticRow...>& st,
span<SpanStaticRow> output,
diagnostics& diag,
Expand Down Expand Up @@ -771,28 +736,19 @@ class any_connection
/// \copydoc connection::async_read_resultset_head
template <
BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_read_resultset_head(
ExecutionStateType& st,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_read_resultset_head(ExecutionStateType& st, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_read_resultset_head_t<CompletionToken>)
{
return async_read_resultset_head(st, impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_read_resultset_head
template <
BOOST_MYSQL_EXECUTION_STATE_TYPE ExecutionStateType,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_read_resultset_head(
ExecutionStateType& st,
diagnostics& diag,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_read_resultset_head(ExecutionStateType& st, diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_read_resultset_head_t<CompletionToken>)
{
return impl_.async_run(
impl_.make_params_read_resultset_head(st, diag),
Expand All @@ -813,19 +769,16 @@ class any_connection
}

/// \copydoc connection::async_ping
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_ping(CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_ping(CompletionToken&& token) BOOST_MYSQL_RETURN_TYPE(detail::async_ping_t<CompletionToken>)
{
return async_ping(impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_ping
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_ping(diagnostics& diag, CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_ping(diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_ping_t<CompletionToken>)
{
return impl_.async_run(impl_.make_params_ping(diag), std::forward<CompletionToken>(token));
}
Expand All @@ -846,22 +799,17 @@ class any_connection
}

/// \copydoc connection::async_reset_connection
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_reset_connection(CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_reset_connection(CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_reset_connection_t<CompletionToken>)
{
return async_reset_connection(impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_reset_connection
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code))
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_reset_connection(
diagnostics& diag,
CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(::boost::mysql::error_code)) CompletionToken>
auto async_reset_connection(diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_reset_connection_t<CompletionToken>)
{
return impl_.async_run(
impl_.make_params_reset_connection(diag),
Expand Down Expand Up @@ -909,16 +857,16 @@ class any_connection
* The handler signature for this operation is `void(boost::mysql::error_code)`.
*/
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_close(CompletionToken&& token)
auto async_close(CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_close_connection_t<CompletionToken>)
{
return async_close(impl_.shared_diag(), std::forward<CompletionToken>(token));
}

/// \copydoc async_close
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code)) CompletionToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code))
async_close(diagnostics& diag, CompletionToken&& token)
auto async_close(diagnostics& diag, CompletionToken&& token)
BOOST_MYSQL_RETURN_TYPE(detail::async_close_connection_t<CompletionToken>)
{
return this->impl_.async_run(
this->impl_.make_params_close(diag),
Expand Down
7 changes: 7 additions & 0 deletions include/boost/mysql/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
#define BOOST_MYSQL_STATIC_OR_INLINE inline
#endif

// Auto return type. Having this as a macro helps the documentation tool.
#ifdef BOOST_NO_CXX14_RETURN_TYPE_DEDUCTION
#define BOOST_MYSQL_RETURN_TYPE(...) -> __VA_ARGS__
#else
#define BOOST_MYSQL_RETURN_TYPE(...)
#endif

// clang-format on

#endif
Loading

0 comments on commit 6a43eeb

Please sign in to comment.