just.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/single_sender.h>
  20. namespace pushmi {
  21. namespace operators {
  22. PUSHMI_INLINE_VAR constexpr struct just_fn {
  23. private:
  24. struct sender_base : single_sender<ignoreSF, inlineEXF> {
  25. using properties = property_set<
  26. is_sender<>,
  27. is_single<>,
  28. is_always_blocking<>,
  29. is_fifo_sequence<>>;
  30. };
  31. template <class... VN>
  32. struct impl {
  33. std::tuple<VN...> vn_;
  34. PUSHMI_TEMPLATE(class Out)
  35. (requires ReceiveValue<Out, VN...>)
  36. void operator()(sender_base&, Out out) {
  37. ::pushmi::apply(
  38. ::pushmi::set_value,
  39. std::tuple_cat(std::tuple<Out&>{out}, std::move(vn_)));
  40. ::pushmi::set_done(std::move(out));
  41. }
  42. };
  43. public:
  44. PUSHMI_TEMPLATE(class... VN)
  45. (requires And<SemiMovable<VN>...>)
  46. auto operator()(VN... vn) const {
  47. return make_single_sender(
  48. sender_base{}, impl<VN...>{std::tuple<VN...>{std::move(vn)...}});
  49. }
  50. } just{};
  51. } // namespace operators
  52. } // namespace pushmi