diff --git a/include/pqxx/transactor.hxx b/include/pqxx/transactor.hxx index eab5c2ffb..928fe67c9 100644 --- a/include/pqxx/transactor.hxx +++ b/include/pqxx/transactor.hxx @@ -14,6 +14,8 @@ #include "pqxx/compiler-public.hxx" #include "pqxx/internal/compiler-internal-pre.hxx" +#include + #include "pqxx/connection.hxx" #include "pqxx/transaction.hxx" @@ -94,8 +96,8 @@ namespace pqxx * @return Whatever your callback returns. */ template -inline auto perform(TRANSACTION_CALLBACK const &callback, int attempts = 3) - -> decltype(callback()) +inline auto perform(TRANSACTION_CALLBACK &&callback, int attempts = 3) + -> decltype(std::invoke(callback)) { if (attempts <= 0) throw std::invalid_argument{ @@ -105,7 +107,7 @@ inline auto perform(TRANSACTION_CALLBACK const &callback, int attempts = 3) { try { - return callback(); + return std::invoke(callback); } catch (in_doubt_error const &) { diff --git a/test/unit/test_transactor.cxx b/test/unit/test_transactor.cxx index 56e01db31..b1fedfb7e 100644 --- a/test/unit/test_transactor.cxx +++ b/test/unit/test_transactor.cxx @@ -19,7 +19,7 @@ void test_transactor_newstyle_executes_simple_query() void test_transactor_newstyle_can_return_void() { bool done{false}; - pqxx::perform([&done] { done = true; }); + pqxx::perform([&done]() noexcept { done = true; }); PQXX_CHECK(done, "Callback was not executed."); } @@ -27,7 +27,7 @@ void test_transactor_newstyle_can_return_void() void test_transactor_newstyle_completes_upon_success() { int attempts{0}; - pqxx::perform([&attempts]() { attempts++; }); + pqxx::perform([&attempts]() noexcept { attempts++; }); PQXX_CHECK_EQUAL(attempts, 1, "Successful transactor didn't run 1 time."); }