Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:38:33

0001 //
0002 // inline_executor.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_INLINE_EXECUTOR_HPP
0012 #define BOOST_ASIO_INLINE_EXECUTOR_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/detail/non_const_lvalue.hpp>
0020 #include <boost/asio/detail/type_traits.hpp>
0021 #include <boost/asio/execution.hpp>
0022 
0023 #include <boost/asio/detail/push_options.hpp>
0024 
0025 namespace boost {
0026 namespace asio {
0027 
0028 /// An executor that always executes the function object inline.
0029 template <typename InlineExceptionHandling>
0030 class basic_inline_executor
0031 {
0032 public:
0033   /// Default constructor.
0034   basic_inline_executor() noexcept
0035   {
0036   }
0037 
0038 #if !defined(GENERATING_DOCUMENTATION)
0039 private:
0040   friend struct boost_asio_require_fn::impl;
0041   friend struct boost_asio_prefer_fn::impl;
0042 #endif // !defined(GENERATING_DOCUMENTATION)
0043 
0044   /// Obtain an executor with the @c inline_exception_handling.propagate
0045   /// property.
0046   /**
0047    * Do not call this function directly. It is intended for use with the
0048    * boost::asio::require customisation point.
0049    *
0050    * For example:
0051    * @code boost::asio::inline_executor ex1;
0052    * auto ex2 = boost::asio::require(ex1,
0053    *     boost::asio::execution::inline_exception_handling.propagate); @endcode
0054    */
0055   basic_inline_executor<execution::inline_exception_handling_t::propagate_t>
0056   require(execution::inline_exception_handling_t::propagate_t) const noexcept
0057   {
0058     return basic_inline_executor<
0059         execution::inline_exception_handling_t::propagate_t>();
0060   }
0061 
0062   /// Obtain an executor with the @c inline_exception_handling.terminate
0063   /// property.
0064   /**
0065    * Do not call this function directly. It is intended for use with the
0066    * boost::asio::require customisation point.
0067    *
0068    * For example:
0069    * @code boost::asio::inline_executor ex1;
0070    * auto ex2 = boost::asio::require(ex1,
0071    *     boost::asio::execution::inline_exception_handling.terminate); @endcode
0072    */
0073   basic_inline_executor<execution::inline_exception_handling_t::terminate_t>
0074   require(execution::inline_exception_handling_t::terminate_t) const noexcept
0075   {
0076     return basic_inline_executor<
0077         execution::inline_exception_handling_t::terminate_t>();
0078   }
0079 
0080 #if !defined(GENERATING_DOCUMENTATION)
0081 private:
0082   friend struct boost_asio_query_fn::impl;
0083   friend struct boost::asio::execution::detail::blocking_t<0>;
0084   friend struct boost::asio::execution::detail::mapping_t<0>;
0085   friend struct boost::asio::execution::detail::inline_exception_handling_t<0>;
0086 #endif // !defined(GENERATING_DOCUMENTATION)
0087 
0088   /// Query the current value of the @c mapping property.
0089   /**
0090    * Do not call this function directly. It is intended for use with the
0091    * boost::asio::query customisation point.
0092    *
0093    * For example:
0094    * @code boost::asio::inline_executor ex;
0095    * if (boost::asio::query(ex, boost::asio::execution::mapping)
0096    *       == boost::asio::execution::mapping.thread)
0097    *   ... @endcode
0098    */
0099   static constexpr execution::mapping_t query(
0100       execution::mapping_t) noexcept
0101   {
0102     return execution::mapping.thread;
0103   }
0104 
0105   /// Query the current value of the @c inline_exception_handling property.
0106   /**
0107    * Do not call this function directly. It is intended for use with the
0108    * boost::asio::query customisation point.
0109    *
0110    * For example:
0111    * @code boost::asio::inline_executor ex;
0112    * if (boost::asio::query(ex,
0113    *       boost::asio::execution::inline_exception_handling)
0114    *     == boost::asio::execution::inline_exception_handling.propagate)
0115    *   ... @endcode
0116    */
0117   static constexpr execution::inline_exception_handling_t query(
0118       execution::inline_exception_handling_t) noexcept
0119   {
0120     return InlineExceptionHandling();
0121   }
0122 
0123   /// Query the current value of the @c blocking property.
0124   /**
0125    * Do not call this function directly. It is intended for use with the
0126    * boost::asio::query customisation point.
0127    *
0128    * For example:
0129    * @code boost::asio::inline_executor ex;
0130    * if (boost::asio::query(ex, boost::asio::execution::blocking)
0131    *     == boost::asio::execution::blocking.always)
0132    *   ... @endcode
0133    */
0134   static constexpr execution::blocking_t query(
0135       execution::blocking_t) noexcept
0136   {
0137     return execution::blocking.always;
0138   }
0139 
0140 public:
0141   /// Compare two executors for equality.
0142   /**
0143    * Two inline executors are always considered equal.
0144    */
0145   friend bool operator==(const basic_inline_executor&,
0146       const basic_inline_executor&) noexcept
0147   {
0148     return true;
0149   }
0150 
0151   /// Compare two executors for inequality.
0152   /**
0153    * Two inline executors are never considered unequal.
0154    */
0155   friend bool operator!=(const basic_inline_executor&,
0156       const basic_inline_executor&) noexcept
0157   {
0158     return false;
0159   }
0160 
0161   /// Execution function.
0162   template <typename Function>
0163   void execute(Function&& f) const
0164   {
0165 #if !defined(BOOST_ASIO_NO_EXCEPTIONS)
0166     try
0167 #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
0168     {
0169       detail::non_const_lvalue<Function> f2(f);
0170       static_cast<decay_t<Function>&&>(f2.value)();
0171     }
0172 #if !defined(BOOST_ASIO_NO_EXCEPTIONS)
0173     catch (...)
0174     {
0175       if (is_same<InlineExceptionHandling,
0176           execution::inline_exception_handling_t::terminate_t>::value)
0177       {
0178         std::terminate();
0179       }
0180       else
0181       {
0182         throw;
0183       }
0184     }
0185 #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
0186   }
0187 };
0188 
0189 /// An executor that always executes the function object inline.
0190 typedef basic_inline_executor<
0191   execution::inline_exception_handling_t::propagate_t>
0192     inline_executor;
0193 
0194 #if !defined(GENERATING_DOCUMENTATION)
0195 
0196 namespace traits {
0197 
0198 #if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
0199 
0200 template <typename InlineExceptionHandling>
0201 struct equality_comparable<
0202     basic_inline_executor<InlineExceptionHandling>
0203   >
0204 {
0205   static constexpr bool is_valid = true;
0206   static constexpr bool is_noexcept = true;
0207 };
0208 
0209 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
0210 
0211 #if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
0212 
0213 template <typename InlineExceptionHandling, typename Function>
0214 struct execute_member<
0215     basic_inline_executor<InlineExceptionHandling>,
0216     Function
0217   >
0218 {
0219   static constexpr bool is_valid = true;
0220   static constexpr bool is_noexcept = false;
0221   typedef void result_type;
0222 };
0223 
0224 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
0225 
0226 #if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
0227 
0228 template <typename InlineExceptionHandling>
0229 struct require_member<
0230     basic_inline_executor<InlineExceptionHandling>,
0231     execution::inline_exception_handling_t::propagate_t
0232   >
0233 {
0234   static constexpr bool is_valid = true;
0235   static constexpr bool is_noexcept = true;
0236   typedef basic_inline_executor<
0237       execution::inline_exception_handling_t::propagate_t>
0238         result_type;
0239 };
0240 
0241 template <typename InlineExceptionHandling>
0242 struct require_member<
0243     basic_inline_executor<InlineExceptionHandling>,
0244     execution::inline_exception_handling_t::terminate_t
0245   >
0246 {
0247   static constexpr bool is_valid = true;
0248   static constexpr bool is_noexcept = true;
0249   typedef basic_inline_executor<
0250       execution::inline_exception_handling_t::terminate_t>
0251         result_type;
0252 };
0253 
0254 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
0255 
0256 #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0257 
0258 template <typename InlineExceptionHandling, typename Property>
0259 struct query_static_constexpr_member<
0260     basic_inline_executor<InlineExceptionHandling>,
0261     Property,
0262     enable_if_t<
0263       is_convertible<
0264         Property,
0265         execution::mapping_t
0266       >::value
0267     >
0268   >
0269 {
0270   static constexpr bool is_valid = true;
0271   static constexpr bool is_noexcept = true;
0272   typedef execution::mapping_t::thread_t result_type;
0273 
0274   static constexpr result_type value() noexcept
0275   {
0276     return result_type();
0277   }
0278 };
0279 
0280 template <typename InlineExceptionHandling, typename Property>
0281 struct query_static_constexpr_member<
0282     basic_inline_executor<InlineExceptionHandling>,
0283     Property,
0284     enable_if_t<
0285       is_convertible<
0286         Property,
0287         execution::inline_exception_handling_t
0288       >::value
0289     >
0290   >
0291 {
0292   static constexpr bool is_valid = true;
0293   static constexpr bool is_noexcept = true;
0294   typedef InlineExceptionHandling result_type;
0295 
0296   static constexpr result_type value() noexcept
0297   {
0298     return result_type();
0299   }
0300 };
0301 
0302 template <typename InlineExceptionHandling, typename Property>
0303 struct query_static_constexpr_member<
0304     basic_inline_executor<InlineExceptionHandling>,
0305     Property,
0306     enable_if_t<
0307       is_convertible<
0308         Property,
0309         execution::blocking_t
0310       >::value
0311     >
0312   >
0313 {
0314   static constexpr bool is_valid = true;
0315   static constexpr bool is_noexcept = true;
0316   typedef execution::blocking_t::always_t result_type;
0317 
0318   static constexpr result_type value() noexcept
0319   {
0320     return result_type();
0321   }
0322 };
0323 
0324 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0325 
0326 } // namespace traits
0327 
0328 #endif // !defined(GENERATING_DOCUMENTATION)
0329 
0330 } // namespace asio
0331 } // namespace boost
0332 
0333 #include <boost/asio/detail/pop_options.hpp>
0334 
0335 #endif // BOOST_ASIO_INLINE_EXECUTOR_HPP