request_via.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. /*
  3. * Copyright 2018-present Facebook, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <folly/experimental/pushmi/o/extension_operators.h>
  18. #include <folly/experimental/pushmi/o/submit.h>
  19. #include <folly/experimental/pushmi/o/via.h>
  20. #include <folly/experimental/pushmi/receiver.h>
  21. namespace pushmi {
  22. template <typename In>
  23. struct send_via {
  24. In in;
  25. PUSHMI_TEMPLATE(class... AN)
  26. (requires Invocable<decltype(::pushmi::operators::via), AN...>&& Invocable<
  27. invoke_result_t<decltype(::pushmi::operators::via), AN...>,
  28. In>)
  29. auto via(AN&&... an) {
  30. return in | ::pushmi::operators::via((AN &&) an...);
  31. }
  32. };
  33. namespace detail {
  34. struct request_via_fn {
  35. private:
  36. struct impl {
  37. PUSHMI_TEMPLATE(class In)
  38. (requires Sender<In>)
  39. auto operator()(In in) const {
  40. return send_via<In>{in};
  41. }
  42. };
  43. public:
  44. inline auto operator()() const {
  45. return impl{};
  46. }
  47. };
  48. } // namespace detail
  49. namespace operators {
  50. PUSHMI_INLINE_VAR constexpr detail::request_via_fn request_via{};
  51. } // namespace operators
  52. PUSHMI_TEMPLATE(class To, class In)
  53. (requires Same<To, is_sender<>>&& Sender<In>)
  54. auto via_cast(In in) {
  55. return in;
  56. }
  57. PUSHMI_TEMPLATE(class To, class In)
  58. (requires Same<To, is_sender<>>)
  59. auto via_cast(send_via<In> ss) {
  60. return ss.in;
  61. }
  62. } // namespace pushmi