Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // execution/allocator.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_EXECUTION_ALLOCATOR_HPP
0012 #define BOOST_ASIO_EXECUTION_ALLOCATOR_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/type_traits.hpp>
0020 #include <boost/asio/execution/executor.hpp>
0021 #include <boost/asio/is_applicable_property.hpp>
0022 #include <boost/asio/traits/query_static_constexpr_member.hpp>
0023 #include <boost/asio/traits/static_query.hpp>
0024 
0025 #include <boost/asio/detail/push_options.hpp>
0026 
0027 namespace boost {
0028 namespace asio {
0029 
0030 #if defined(GENERATING_DOCUMENTATION)
0031 
0032 namespace execution {
0033 
0034 /// A property to describe which allocator an executor will use to allocate the
0035 /// memory required to store a submitted function object.
0036 template <typename ProtoAllocator>
0037 struct allocator_t
0038 {
0039   /// The allocator_t property applies to executors.
0040   template <typename T>
0041   static constexpr bool is_applicable_property_v = is_executor_v<T>;
0042 
0043   /// The allocator_t property can be required.
0044   static constexpr bool is_requirable = true;
0045 
0046   /// The allocator_t property can be preferred.
0047   static constexpr bool is_preferable = true;
0048 
0049   /// Default constructor.
0050   constexpr allocator_t();
0051 
0052   /// Obtain the allocator stored in the allocator_t property object.
0053   /**
0054    * Present only if @c ProtoAllocator is non-void.
0055    */
0056   constexpr ProtoAllocator value() const;
0057 
0058   /// Create an allocator_t object with a different allocator.
0059   /**
0060    * Present only if @c ProtoAllocator is void.
0061    */
0062   template <typename OtherAllocator>
0063   allocator_t<OtherAllocator operator()(const OtherAllocator& a);
0064 };
0065 
0066 /// A special value used for accessing the allocator_t property.
0067 constexpr allocator_t<void> allocator;
0068 
0069 } // namespace execution
0070 
0071 #else // defined(GENERATING_DOCUMENTATION)
0072 
0073 namespace execution {
0074 
0075 template <typename ProtoAllocator>
0076 struct allocator_t
0077 {
0078 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0079   template <typename T>
0080   static constexpr bool is_applicable_property_v = is_executor<T>::value;
0081 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0082 
0083   static constexpr bool is_requirable = true;
0084   static constexpr bool is_preferable = true;
0085 
0086   template <typename T>
0087   struct static_proxy
0088   {
0089 #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0090     struct type
0091     {
0092       template <typename P>
0093       static constexpr auto query(P&& p)
0094         noexcept(
0095           noexcept(
0096             conditional_t<true, T, P>::query(static_cast<P&&>(p))
0097           )
0098         )
0099         -> decltype(
0100           conditional_t<true, T, P>::query(static_cast<P&&>(p))
0101         )
0102       {
0103         return T::query(static_cast<P&&>(p));
0104       }
0105     };
0106 #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0107     typedef T type;
0108 #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0109   };
0110 
0111   template <typename T>
0112   struct query_static_constexpr_member :
0113     traits::query_static_constexpr_member<
0114       typename static_proxy<T>::type, allocator_t> {};
0115 
0116 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0117   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0118   template <typename T>
0119   static constexpr typename query_static_constexpr_member<T>::result_type
0120   static_query()
0121     noexcept(query_static_constexpr_member<T>::is_noexcept)
0122   {
0123     return query_static_constexpr_member<T>::value();
0124   }
0125 
0126   template <typename E, typename T = decltype(allocator_t::static_query<E>())>
0127   static constexpr const T static_query_v = allocator_t::static_query<E>();
0128 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0129        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0130 
0131   constexpr ProtoAllocator value() const
0132   {
0133     return a_;
0134   }
0135 
0136 private:
0137   friend struct allocator_t<void>;
0138 
0139   explicit constexpr allocator_t(const ProtoAllocator& a)
0140     : a_(a)
0141   {
0142   }
0143 
0144   ProtoAllocator a_;
0145 };
0146 
0147 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0148   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0149 template <typename ProtoAllocator> template <typename E, typename T>
0150 const T allocator_t<ProtoAllocator>::static_query_v;
0151 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0152        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0153 
0154 template <>
0155 struct allocator_t<void>
0156 {
0157 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0158   template <typename T>
0159   static constexpr bool is_applicable_property_v = is_executor<T>::value;
0160 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0161 
0162   static constexpr bool is_requirable = true;
0163   static constexpr bool is_preferable = true;
0164 
0165   constexpr allocator_t()
0166   {
0167   }
0168 
0169   template <typename T>
0170   struct static_proxy
0171   {
0172 #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0173     struct type
0174     {
0175       template <typename P>
0176       static constexpr auto query(P&& p)
0177         noexcept(
0178           noexcept(
0179             conditional_t<true, T, P>::query(static_cast<P&&>(p))
0180           )
0181         )
0182         -> decltype(
0183           conditional_t<true, T, P>::query(static_cast<P&&>(p))
0184         )
0185       {
0186         return T::query(static_cast<P&&>(p));
0187       }
0188     };
0189 #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0190     typedef T type;
0191 #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0192   };
0193 
0194   template <typename T>
0195   struct query_static_constexpr_member :
0196     traits::query_static_constexpr_member<
0197       typename static_proxy<T>::type, allocator_t> {};
0198 
0199 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0200   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0201   template <typename T>
0202   static constexpr typename query_static_constexpr_member<T>::result_type
0203   static_query()
0204     noexcept(query_static_constexpr_member<T>::is_noexcept)
0205   {
0206     return query_static_constexpr_member<T>::value();
0207   }
0208 
0209   template <typename E, typename T = decltype(allocator_t::static_query<E>())>
0210   static constexpr const T static_query_v = allocator_t::static_query<E>();
0211 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0212        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0213 
0214   template <typename OtherProtoAllocator>
0215   constexpr allocator_t<OtherProtoAllocator> operator()(
0216       const OtherProtoAllocator& a) const
0217   {
0218     return allocator_t<OtherProtoAllocator>(a);
0219   }
0220 };
0221 
0222 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0223   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0224 template <typename E, typename T>
0225 const T allocator_t<void>::static_query_v;
0226 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0227        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0228 
0229 BOOST_ASIO_INLINE_VARIABLE constexpr allocator_t<void> allocator;
0230 
0231 } // namespace execution
0232 
0233 #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0234 
0235 template <typename T, typename ProtoAllocator>
0236 struct is_applicable_property<T, execution::allocator_t<ProtoAllocator>>
0237   : integral_constant<bool, execution::is_executor<T>::value>
0238 {
0239 };
0240 
0241 #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0242 
0243 namespace traits {
0244 
0245 #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0246   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0247 
0248 template <typename T, typename ProtoAllocator>
0249 struct static_query<T, execution::allocator_t<ProtoAllocator>,
0250   enable_if_t<
0251     execution::allocator_t<ProtoAllocator>::template
0252       query_static_constexpr_member<T>::is_valid
0253   >>
0254 {
0255   static constexpr bool is_valid = true;
0256   static constexpr bool is_noexcept = true;
0257 
0258   typedef typename execution::allocator_t<ProtoAllocator>::template
0259     query_static_constexpr_member<T>::result_type result_type;
0260 
0261   static constexpr result_type value()
0262   {
0263     return execution::allocator_t<ProtoAllocator>::template
0264       query_static_constexpr_member<T>::value();
0265   }
0266 };
0267 
0268 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
0269        //   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0270 
0271 } // namespace traits
0272 
0273 #endif // defined(GENERATING_DOCUMENTATION)
0274 
0275 } // namespace asio
0276 } // namespace boost
0277 
0278 #include <boost/asio/detail/pop_options.hpp>
0279 
0280 #endif // BOOST_ASIO_EXECUTION_ALLOCATOR_HPP