/* * Copyright (c) Facebook, Inc. and its affiliates. * * Licensed under the Apache License Version 2.0 with LLVM Exceptions * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://llvm.org/LICENSE.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include namespace unifex { namespace _demat { template struct _receiver { class type; }; template using receiver_t = typename _receiver>::type; template class _receiver::type { public: template(typename Receiver2) (requires constructible_from) explicit type(Receiver2&& receiver) noexcept( std::is_nothrow_constructible_v) : receiver_(static_cast(receiver)) {} template(typename CPO, typename... Values) (requires is_receiver_cpo_v AND is_callable_v) void set_value(CPO cpo, Values&&... values) && noexcept( is_nothrow_callable_v) { static_cast(cpo)( static_cast(receiver_), static_cast(values)...); } template(typename Error) (requires receiver) void set_error(Error&& error) && noexcept { unifex::set_error( static_cast(receiver_), static_cast(error)); } void set_done() && noexcept { unifex::set_done(static_cast(receiver_)); } template(typename CPO, UNIFEX_DECLARE_NON_DEDUCED_TYPE(R, type)) (requires is_receiver_query_cpo_v AND is_callable_v) friend auto tag_invoke(CPO cpo, const UNIFEX_USE_NON_DEDUCED_TYPE(R, type)& r) noexcept(is_nothrow_callable_v) -> callable_result_t { return static_cast(cpo)(std::as_const(r.receiver_)); } template friend void tag_invoke(tag_t, const type& r, Func&& func) noexcept(std:: is_nothrow_invocable_v< Func&, const Receiver&>) { std::invoke(func, std::as_const(r.receiver_)); } private: Receiver receiver_; }; template class Tuple> struct tuple { private: template struct apply_impl; template struct apply_impl : std::conditional< std::is_base_of_v>, type_list>, type_list<>> {}; public: template using apply = typename apply_impl::type; }; template