Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use_future.hpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // use_future.hpp
  3. // ~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_USE_FUTURE_HPP
  11. #define ASIO_USE_FUTURE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <memory>
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. /// Class used to specify that an asynchronous operation should return a future.
  20. /**
  21. * The use_future_t class is used to indicate that an asynchronous operation
  22. * should return a std::future object. A use_future_t object may be passed as a
  23. * handler to an asynchronous operation, typically using the special value @c
  24. * asio::use_future. For example:
  25. *
  26. * @code std::future<std::size_t> my_future
  27. * = my_socket.async_read_some(my_buffer, asio::use_future); @endcode
  28. *
  29. * The initiating function (async_read_some in the above example) returns a
  30. * future that will receive the result of the operation. If the operation
  31. * completes with an error_code indicating failure, it is converted into a
  32. * system_error and passed back to the caller via the future.
  33. */
  34. template <typename Allocator = std::allocator<void> >
  35. class use_future_t
  36. {
  37. public:
  38. /// The allocator type. The allocator is used when constructing the
  39. /// @c std::promise object for a given asynchronous operation.
  40. typedef Allocator allocator_type;
  41. /// Construct using default-constructed allocator.
  42. ASIO_CONSTEXPR use_future_t()
  43. {
  44. }
  45. /// Construct using specified allocator.
  46. explicit use_future_t(const Allocator& allocator)
  47. : allocator_(allocator)
  48. {
  49. }
  50. #if !defined(ASIO_NO_DEPRECATED)
  51. /// (Deprecated: Use rebind().) Specify an alternate allocator.
  52. template <typename OtherAllocator>
  53. use_future_t<OtherAllocator> operator[](const OtherAllocator& allocator) const
  54. {
  55. return use_future_t<OtherAllocator>(allocator);
  56. }
  57. #endif // !defined(ASIO_NO_DEPRECATED)
  58. /// Specify an alternate allocator.
  59. template <typename OtherAllocator>
  60. use_future_t<OtherAllocator> rebind(const OtherAllocator& allocator) const
  61. {
  62. return use_future_t<OtherAllocator>(allocator);
  63. }
  64. /// Obtain allocator.
  65. allocator_type get_allocator() const
  66. {
  67. return allocator_;
  68. }
  69. private:
  70. Allocator allocator_;
  71. };
  72. /// A special value, similar to std::nothrow.
  73. /**
  74. * See the documentation for asio::use_future_t for a usage example.
  75. */
  76. #if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
  77. constexpr use_future_t<> use_future;
  78. #elif defined(ASIO_MSVC)
  79. __declspec(selectany) use_future_t<> use_future;
  80. #endif
  81. } // namespace asio
  82. #include "asio/detail/pop_options.hpp"
  83. #include "asio/impl/use_future.hpp"
  84. #endif // ASIO_USE_FUTURE_HPP