initiation_base.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MYSQL_DETAIL_INITIATION_BASE_HPP
  8. #define BOOST_MYSQL_DETAIL_INITIATION_BASE_HPP
  9. #include <boost/mysql/with_diagnostics.hpp>
  10. #include <boost/asio/any_io_executor.hpp>
  11. #include <boost/asio/associator.hpp>
  12. #include <boost/asio/deferred.hpp>
  13. #include <type_traits>
  14. namespace boost {
  15. namespace mysql {
  16. namespace detail {
  17. struct executor_with_default : asio::any_io_executor
  18. {
  19. using default_completion_token_type = with_diagnostics_t<asio::deferred_t>;
  20. template <
  21. typename InnerExecutor1,
  22. class = typename std::enable_if<!std::is_same<InnerExecutor1, executor_with_default>::value>::type>
  23. executor_with_default(const InnerExecutor1& ex) noexcept : asio::any_io_executor(ex)
  24. {
  25. }
  26. };
  27. // Base class for initiation objects. Includes a bound executor, so they're compatible
  28. // with asio::cancel_after and similar. The bound executor has our default completion token.
  29. // Use only in the ops that should use this token.
  30. struct initiation_base
  31. {
  32. executor_with_default ex;
  33. initiation_base(asio::any_io_executor ex) noexcept : ex(std::move(ex)) {}
  34. using executor_type = executor_with_default;
  35. const executor_type& get_executor() const noexcept { return ex; }
  36. };
  37. } // namespace detail
  38. } // namespace mysql
  39. } // namespace boost
  40. #endif