123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- //
- // execution/allocator.hpp
- // ~~~~~~~~~~~~~~~~~~~~~~~
- //
- // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- #ifndef BOOST_ASIO_EXECUTION_ALLOCATOR_HPP
- #define BOOST_ASIO_EXECUTION_ALLOCATOR_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
- #include <boost/asio/detail/config.hpp>
- #include <boost/asio/detail/type_traits.hpp>
- #include <boost/asio/execution/executor.hpp>
- #include <boost/asio/execution/scheduler.hpp>
- #include <boost/asio/execution/sender.hpp>
- #include <boost/asio/is_applicable_property.hpp>
- #include <boost/asio/traits/query_static_constexpr_member.hpp>
- #include <boost/asio/traits/static_query.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- #if defined(GENERATING_DOCUMENTATION)
- namespace execution {
- /// A property to describe which allocator an executor will use to allocate the
- /// memory required to store a submitted function object.
- template <typename ProtoAllocator>
- struct allocator_t
- {
- /// The allocator_t property applies to executors, senders, and schedulers.
- template <typename T>
- static constexpr bool is_applicable_property_v =
- is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
- /// The allocator_t property can be required.
- static constexpr bool is_requirable = true;
- /// The allocator_t property can be preferred.
- static constexpr bool is_preferable = true;
- /// Default constructor.
- constexpr allocator_t();
- /// Obtain the allocator stored in the allocator_t property object.
- /**
- * Present only if @c ProtoAllocator is non-void.
- */
- constexpr ProtoAllocator value() const;
- /// Create an allocator_t object with a different allocator.
- /**
- * Present only if @c ProtoAllocator is void.
- */
- template <typename OtherAllocator>
- allocator_t<OtherAllocator operator()(const OtherAllocator& a);
- };
- /// A special value used for accessing the allocator_t property.
- constexpr allocator_t<void> allocator;
- } // namespace execution
- #else // defined(GENERATING_DOCUMENTATION)
- namespace execution {
- template <typename ProtoAllocator>
- struct allocator_t
- {
- #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
- template <typename T>
- BOOST_ASIO_STATIC_CONSTEXPR(bool,
- is_applicable_property_v = (
- is_executor<T>::value
- || conditional<
- is_executor<T>::value,
- false_type,
- is_sender<T>
- >::type::value
- || conditional<
- is_executor<T>::value,
- false_type,
- is_scheduler<T>
- >::type::value));
- #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
- BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
- BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
- template <typename T>
- struct static_proxy
- {
- #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
- struct type
- {
- template <typename P>
- static constexpr auto query(BOOST_ASIO_MOVE_ARG(P) p)
- noexcept(
- noexcept(
- conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
- )
- )
- -> decltype(
- conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
- )
- {
- return T::query(BOOST_ASIO_MOVE_CAST(P)(p));
- }
- };
- #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
- typedef T type;
- #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
- };
- template <typename T>
- struct query_static_constexpr_member :
- traits::query_static_constexpr_member<
- typename static_proxy<T>::type, allocator_t> {};
- #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
- && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- template <typename T>
- static BOOST_ASIO_CONSTEXPR
- typename query_static_constexpr_member<T>::result_type
- static_query()
- BOOST_ASIO_NOEXCEPT_IF((
- query_static_constexpr_member<T>::is_noexcept))
- {
- return query_static_constexpr_member<T>::value();
- }
- template <typename E, typename T = decltype(allocator_t::static_query<E>())>
- static BOOST_ASIO_CONSTEXPR const T static_query_v
- = allocator_t::static_query<E>();
- #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
- // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- BOOST_ASIO_CONSTEXPR ProtoAllocator value() const
- {
- return a_;
- }
- private:
- friend struct allocator_t<void>;
- explicit BOOST_ASIO_CONSTEXPR allocator_t(const ProtoAllocator& a)
- : a_(a)
- {
- }
- ProtoAllocator a_;
- };
- #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
- && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- template <typename ProtoAllocator> template <typename E, typename T>
- const T allocator_t<ProtoAllocator>::static_query_v;
- #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
- // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- template <>
- struct allocator_t<void>
- {
- #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
- template <typename T>
- BOOST_ASIO_STATIC_CONSTEXPR(bool,
- is_applicable_property_v = (
- is_executor<T>::value
- || conditional<
- is_executor<T>::value,
- false_type,
- is_sender<T>
- >::type::value
- || conditional<
- is_executor<T>::value,
- false_type,
- is_scheduler<T>
- >::type::value));
- #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
- BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
- BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
- BOOST_ASIO_CONSTEXPR allocator_t()
- {
- }
- template <typename T>
- struct static_proxy
- {
- #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
- struct type
- {
- template <typename P>
- static constexpr auto query(BOOST_ASIO_MOVE_ARG(P) p)
- noexcept(
- noexcept(
- conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
- )
- )
- -> decltype(
- conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
- )
- {
- return T::query(BOOST_ASIO_MOVE_CAST(P)(p));
- }
- };
- #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
- typedef T type;
- #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
- };
- template <typename T>
- struct query_static_constexpr_member :
- traits::query_static_constexpr_member<
- typename static_proxy<T>::type, allocator_t> {};
- #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
- && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- template <typename T>
- static BOOST_ASIO_CONSTEXPR
- typename query_static_constexpr_member<T>::result_type
- static_query()
- BOOST_ASIO_NOEXCEPT_IF((
- query_static_constexpr_member<T>::is_noexcept))
- {
- return query_static_constexpr_member<T>::value();
- }
- template <typename E, typename T = decltype(allocator_t::static_query<E>())>
- static BOOST_ASIO_CONSTEXPR const T static_query_v
- = allocator_t::static_query<E>();
- #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
- // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- template <typename OtherProtoAllocator>
- BOOST_ASIO_CONSTEXPR allocator_t<OtherProtoAllocator> operator()(
- const OtherProtoAllocator& a) const
- {
- return allocator_t<OtherProtoAllocator>(a);
- }
- };
- #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
- && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- template <typename E, typename T>
- const T allocator_t<void>::static_query_v;
- #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
- // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- #if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
- constexpr allocator_t<void> allocator;
- #else // defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
- template <typename T>
- struct allocator_instance
- {
- static allocator_t<T> instance;
- };
- template <typename T>
- allocator_t<T> allocator_instance<T>::instance;
- namespace {
- static const allocator_t<void>& allocator = allocator_instance<void>::instance;
- } // namespace
- #endif
- } // namespace execution
- #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
- template <typename T, typename ProtoAllocator>
- struct is_applicable_property<T, execution::allocator_t<ProtoAllocator> >
- : integral_constant<bool,
- execution::is_executor<T>::value
- || conditional<
- execution::is_executor<T>::value,
- false_type,
- execution::is_sender<T>
- >::type::value
- || conditional<
- execution::is_executor<T>::value,
- false_type,
- execution::is_scheduler<T>
- >::type::value>
- {
- };
- #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
- namespace traits {
- #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
- || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- template <typename T, typename ProtoAllocator>
- struct static_query<T, execution::allocator_t<ProtoAllocator>,
- typename enable_if<
- execution::allocator_t<ProtoAllocator>::template
- query_static_constexpr_member<T>::is_valid
- >::type>
- {
- BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
- BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
- typedef typename execution::allocator_t<ProtoAllocator>::template
- query_static_constexpr_member<T>::result_type result_type;
- static BOOST_ASIO_CONSTEXPR result_type value()
- {
- return execution::allocator_t<ProtoAllocator>::template
- query_static_constexpr_member<T>::value();
- }
- };
- #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
- // || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
- } // namespace traits
- #endif // defined(GENERATING_DOCUMENTATION)
- } // namespace asio
- } // namespace boost
- #include <boost/asio/detail/pop_options.hpp>
- #endif // BOOST_ASIO_EXECUTION_ALLOCATOR_HPP
|