123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #ifndef BOOST_ASIO_ASSOCIATED_ALLOCATOR_HPP
- #define BOOST_ASIO_ASSOCIATED_ALLOCATOR_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/config.hpp>
- #include <memory>
- #include <boost/asio/associator.hpp>
- #include <boost/asio/detail/functional.hpp>
- #include <boost/asio/detail/type_traits.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- template <typename T, typename Allocator>
- struct associated_allocator;
- namespace detail {
- template <typename T, typename = void>
- struct has_allocator_type : false_type
- {
- };
- template <typename T>
- struct has_allocator_type<T, void_t<typename T::allocator_type>> : true_type
- {
- };
- template <typename T, typename A, typename = void, typename = void>
- struct associated_allocator_impl
- {
- typedef void asio_associated_allocator_is_unspecialised;
- typedef A type;
- static type get(const T&) noexcept
- {
- return type();
- }
- static const type& get(const T&, const A& a) noexcept
- {
- return a;
- }
- };
- template <typename T, typename A>
- struct associated_allocator_impl<T, A, void_t<typename T::allocator_type>>
- {
- typedef typename T::allocator_type type;
- static auto get(const T& t) noexcept
- -> decltype(t.get_allocator())
- {
- return t.get_allocator();
- }
- static auto get(const T& t, const A&) noexcept
- -> decltype(t.get_allocator())
- {
- return t.get_allocator();
- }
- };
- template <typename T, typename A>
- struct associated_allocator_impl<T, A,
- enable_if_t<
- !has_allocator_type<T>::value
- >,
- void_t<
- typename associator<associated_allocator, T, A>::type
- >> : associator<associated_allocator, T, A>
- {
- };
- }
- template <typename T, typename Allocator = std::allocator<void>>
- struct associated_allocator
- #if !defined(GENERATING_DOCUMENTATION)
- : detail::associated_allocator_impl<T, Allocator>
- #endif
- {
- #if defined(GENERATING_DOCUMENTATION)
-
-
- typedef see_below type;
-
-
- static decltype(auto) get(const T& t) noexcept;
-
-
- static decltype(auto) get(const T& t, const Allocator& a) noexcept;
- #endif
- };
- template <typename T>
- BOOST_ASIO_NODISCARD inline typename associated_allocator<T>::type
- get_associated_allocator(const T& t) noexcept
- {
- return associated_allocator<T>::get(t);
- }
- template <typename T, typename Allocator>
- BOOST_ASIO_NODISCARD inline auto get_associated_allocator(
- const T& t, const Allocator& a) noexcept
- -> decltype(associated_allocator<T, Allocator>::get(t, a))
- {
- return associated_allocator<T, Allocator>::get(t, a);
- }
- template <typename T, typename Allocator = std::allocator<void>>
- using associated_allocator_t
- = typename associated_allocator<T, Allocator>::type;
- namespace detail {
- template <typename T, typename A, typename = void>
- struct associated_allocator_forwarding_base
- {
- };
- template <typename T, typename A>
- struct associated_allocator_forwarding_base<T, A,
- enable_if_t<
- is_same<
- typename associated_allocator<T,
- A>::asio_associated_allocator_is_unspecialised,
- void
- >::value
- >>
- {
- typedef void asio_associated_allocator_is_unspecialised;
- };
- }
- template <typename T, typename Allocator>
- struct associated_allocator<reference_wrapper<T>, Allocator>
- #if !defined(GENERATING_DOCUMENTATION)
- : detail::associated_allocator_forwarding_base<T, Allocator>
- #endif
- {
-
-
- typedef typename associated_allocator<T, Allocator>::type type;
-
-
- static type get(reference_wrapper<T> t) noexcept
- {
- return associated_allocator<T, Allocator>::get(t.get());
- }
-
-
- static auto get(reference_wrapper<T> t, const Allocator& a) noexcept
- -> decltype(associated_allocator<T, Allocator>::get(t.get(), a))
- {
- return associated_allocator<T, Allocator>::get(t.get(), a);
- }
- };
- }
- }
- #include <boost/asio/detail/pop_options.hpp>
- #endif
|