write.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // Copyright (c) 2025 Klemens Morgenstern (klemens.morgenstern@gmx.net)
  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_COBALT_IO_WRITE_HPP
  8. #define BOOST_COBALT_IO_WRITE_HPP
  9. #include <boost/cobalt/io/detail/config.hpp>
  10. #include <boost/cobalt/io/buffer.hpp>
  11. #include <boost/cobalt/io/ops.hpp>
  12. #include <concepts>
  13. namespace boost::cobalt::io
  14. {
  15. struct BOOST_COBALT_IO_DECL write_all final : op<system::error_code, std::size_t>
  16. {
  17. write_op step;
  18. write_all(write_op op) : step(op) {}
  19. ~write_all() = default;
  20. void initiate(completion_handler<system::error_code, std::size_t>) final;
  21. };
  22. template<typename Stream>
  23. requires requires (Stream & str, const_buffer_sequence buffer)
  24. {
  25. {str.write_some(buffer)} -> std::same_as<write_op>;
  26. }
  27. [[nodiscard]] BOOST_COBALT_MSVC_NOINLINE
  28. write_all write(Stream & str, const_buffer_sequence buffer)
  29. {
  30. return write_all{str.write_some(buffer)};
  31. }
  32. struct BOOST_COBALT_IO_DECL write_all_at final : op<system::error_code, std::size_t>
  33. {
  34. write_at_op step;
  35. write_all_at(write_at_op op) : step(op) {}
  36. ~write_all_at() = default;
  37. void initiate(completion_handler<system::error_code, std::size_t>) final;
  38. };
  39. template<typename Stream>
  40. requires requires (Stream & str, std::uint64_t offset, const_buffer_sequence buffer)
  41. {
  42. {str.write_some_at(offset, buffer)} -> std::same_as<write_op>;
  43. }
  44. [[nodiscard]] BOOST_COBALT_MSVC_NOINLINE
  45. write_all_at write_at(Stream & str, std::uint64_t offset, const_buffer_sequence buffer)
  46. {
  47. return write_all_at{str.write_some_at(offset, buffer)};
  48. }
  49. }
  50. #endif //BOOST_COBALT_IO_WRITE_HPP