Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:43:20

0001 //
0002 // experimental/cancellation_condition.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_EXPERIMENTAL_CANCELLATION_CONDITION_HPP
0012 #define BOOST_ASIO_EXPERIMENTAL_CANCELLATION_CONDITION_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/cancellation_type.hpp>
0020 #include <boost/asio/disposition.hpp>
0021 #include <boost/asio/detail/type_traits.hpp>
0022 
0023 #include <boost/asio/detail/push_options.hpp>
0024 
0025 namespace boost {
0026 namespace asio {
0027 namespace experimental {
0028 
0029 /// Wait for all operations to complete.
0030 class wait_for_all
0031 {
0032 public:
0033   template <typename... Args>
0034   constexpr cancellation_type_t operator()(Args&&...) const noexcept
0035   {
0036     return cancellation_type::none;
0037   }
0038 };
0039 
0040 /// Wait until an operation completes, then cancel the others.
0041 class wait_for_one
0042 {
0043 public:
0044   constexpr explicit wait_for_one(
0045       cancellation_type_t cancel_type = cancellation_type::all)
0046     : cancel_type_(cancel_type)
0047   {
0048   }
0049 
0050   template <typename... Args>
0051   constexpr cancellation_type_t operator()(Args&&...) const noexcept
0052   {
0053     return cancel_type_;
0054   }
0055 
0056 private:
0057   cancellation_type_t cancel_type_;
0058 };
0059 
0060 /// Wait until an operation completes without an error, then cancel the others.
0061 /**
0062  * If no operation completes without an error, waits for completion of all
0063  * operations.
0064  */
0065 class wait_for_one_success
0066 {
0067 public:
0068   constexpr explicit wait_for_one_success(
0069       cancellation_type_t cancel_type = cancellation_type::all)
0070     : cancel_type_(cancel_type)
0071   {
0072   }
0073 
0074   constexpr cancellation_type_t
0075   operator()() const noexcept
0076   {
0077     return cancel_type_;
0078   }
0079 
0080   template <typename E, typename... Args>
0081   constexpr constraint_t<!is_disposition<E>::value, cancellation_type_t>
0082   operator()(const E&, Args&&...) const noexcept
0083   {
0084     return cancel_type_;
0085   }
0086 
0087   template <typename E, typename... Args>
0088   constexpr constraint_t<is_disposition<E>::value, cancellation_type_t>
0089   operator()(const E& e, Args&&...) const noexcept
0090   {
0091     return e != no_error ? cancellation_type::none : cancel_type_;
0092   }
0093 
0094 private:
0095   cancellation_type_t cancel_type_;
0096 };
0097 
0098 /// Wait until an operation completes with an error, then cancel the others.
0099 /**
0100  * If no operation completes with an error, waits for completion of all
0101  * operations.
0102  */
0103 class wait_for_one_error
0104 {
0105 public:
0106   constexpr explicit wait_for_one_error(
0107       cancellation_type_t cancel_type = cancellation_type::all)
0108     : cancel_type_(cancel_type)
0109   {
0110   }
0111 
0112   constexpr cancellation_type_t operator()() const noexcept
0113   {
0114     return cancellation_type::none;
0115   }
0116 
0117   template <typename E, typename... Args>
0118   constexpr constraint_t<!is_disposition<E>::value, cancellation_type_t>
0119   operator()(const E&, Args&&...) const noexcept
0120   {
0121     return cancellation_type::none;
0122   }
0123 
0124   template <typename E, typename... Args>
0125   constexpr constraint_t<is_disposition<E>::value, cancellation_type_t>
0126   operator()(const E& e, Args&&...) const noexcept
0127   {
0128     return e != no_error ? cancel_type_ : cancellation_type::none;
0129   }
0130 
0131 private:
0132   cancellation_type_t cancel_type_;
0133 };
0134 
0135 } // namespace experimental
0136 } // namespace asio
0137 } // namespace boost
0138 
0139 #include <boost/asio/detail/pop_options.hpp>
0140 
0141 #endif // BOOST_ASIO_EXPERIMENTAL_CANCELLATION_CONDITION_HPP