Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-26 08:26:30

0001 //
0002 // Copyright (c) 2024 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_NOOP_HPP
0009 #define BOOST_COBALT_NOOP_HPP
0010 
0011 #include <type_traits>
0012 #include <utility>
0013 
0014 namespace boost::cobalt
0015 {
0016 
0017 
0018 // tag::outline[]
0019 // This is a tag type allowing the creation of promises or generators without creating a coroutine.
0020 template<typename T = void>
0021 struct noop
0022 {
0023   template<typename ... Args>
0024   constexpr noop(Args && ... args) noexcept(std::is_nothrow_constructible_v<T, Args&&...>)
0025     : value(std::forward<Args>(args)...)
0026   {
0027   }
0028   // end::outline[]
0029   T value;
0030 
0031   constexpr static bool await_ready() {return true;}
0032   template<typename P>
0033   constexpr static void await_suspend(std::coroutine_handle<P>) {}
0034   constexpr T await_resume() {return std::move(value);}
0035 
0036   // tag::outline[]
0037 };
0038 // end::outline[]
0039 
0040 template<> struct noop<void>
0041 {
0042   constexpr static bool await_ready() {return true;}
0043   template<typename P>
0044   constexpr static void await_suspend(std::coroutine_handle<P>) {}
0045   constexpr static void await_resume() {}
0046 };
0047 
0048 
0049 template<typename T> noop(      T &&) -> noop<T>;
0050 template<typename T> noop(const T & ) -> noop<T>;
0051 noop() -> noop<void>;
0052 
0053 }
0054 
0055 #endif //BOOST_COBALT_NOOP_HPP