Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:34:31

0001 //
0002 // Copyright (c) 2022 Klemens Morgenstern (klemens.morgenstern@gmx.net)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_COBALT_DETAIL_THIS_THREAD_HPP
0009 #define BOOST_COBALT_DETAIL_THIS_THREAD_HPP
0010 
0011 #include <boost/cobalt/this_thread.hpp>
0012 
0013 #include <boost/asio/uses_executor.hpp>
0014 #include <boost/mp11/algorithm.hpp>
0015 
0016 namespace boost::cobalt::detail
0017 {
0018 
0019 inline executor
0020 extract_executor(executor exec) { return exec; }
0021 
0022 #if defined(BOOST_COBALT_CUSTOM_EXECUTOR) || defined(BOOST_COBALT_USE_IO_CONTEXT)
0023 BOOST_COBALT_DECL executor
0024 extract_executor(asio::any_io_executor exec);
0025 #endif
0026 
0027 template<typename ... Args>
0028 executor get_executor_from_args(Args &&... args)
0029 {
0030   using args_type = mp11::mp_list<std::decay_t<Args>...>;
0031   constexpr static auto I = mp11::mp_find<args_type, asio::executor_arg_t>::value;
0032   if constexpr (sizeof...(Args) == I)
0033     return this_thread::get_executor();
0034   else  //
0035     return extract_executor(std::get<I + 1u>(std::tie(args...)));
0036 }
0037 
0038 #if !defined(BOOST_COBALT_NO_PMR)
0039 template<typename ... Args>
0040 pmr::memory_resource * get_memory_resource_from_args(Args &&... args)
0041 {
0042   using args_type = mp11::mp_list<std::decay_t<Args>...>;
0043   constexpr static auto I = mp11::mp_find<args_type, std::allocator_arg_t>::value;
0044   if constexpr (sizeof...(Args) == I)
0045     return this_thread::get_default_resource();
0046   else  //
0047     return std::get<I + 1u>(std::tie(args...)).resource();
0048 }
0049 
0050 template<typename ... Args>
0051 pmr::memory_resource * get_memory_resource_from_args_global(Args &&... args)
0052 {
0053   using args_type = mp11::mp_list<std::decay_t<Args>...>;
0054   constexpr static auto I = mp11::mp_find<args_type, std::allocator_arg_t>::value;
0055   if constexpr (sizeof...(Args) == I)
0056     return pmr::get_default_resource();
0057   else  //
0058     return std::get<I + 1u>(std::tie(args...)).resource();
0059 }
0060 #endif
0061 
0062 }
0063 
0064 #endif //BOOST_COBALT_DETAIL_THIS_THREAD_HPP