|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | + * Copyright (c) 2025 Robert Leahy. All rights reserved. |
| 4 | + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://llvm.org/LICENSE.txt |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#pragma once |
| 20 | + |
| 21 | +#include <type_traits> |
| 22 | +#include <utility> |
| 23 | +#include <asioexec/asio_config.hpp> |
| 24 | +#include <asioexec/executor_with_default.hpp> |
| 25 | + |
| 26 | +namespace asioexec { |
| 27 | + |
| 28 | + template <typename CompletionToken, typename IoObject> |
| 29 | + using as_default_on_t = |
| 30 | + typename std::remove_cvref_t<IoObject>::template rebind_executor<executor_with_default< |
| 31 | + std::remove_cvref_t<decltype(std::declval<IoObject&>().get_executor())>, |
| 32 | + CompletionToken>>::other; |
| 33 | + |
| 34 | + namespace detail::as_default_on { |
| 35 | + |
| 36 | + template <typename CompletionToken> |
| 37 | + struct t { |
| 38 | + template <typename IoObject> |
| 39 | + constexpr asioexec::as_default_on_t<CompletionToken, IoObject> |
| 40 | + operator()(IoObject&& io) const { |
| 41 | + return asioexec::as_default_on_t<CompletionToken, IoObject>((IoObject&&) io); |
| 42 | + } |
| 43 | + }; |
| 44 | + |
| 45 | + } // namespace detail::as_default_on |
| 46 | + |
| 47 | + template <typename CompletionToken> |
| 48 | + inline constexpr detail::as_default_on::t<CompletionToken> as_default_on; |
| 49 | + |
| 50 | +} // namespace asioexec |
0 commit comments