no_fail.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/submit.h>
  18. #include <folly/experimental/pushmi/single_sender.h>
  19. namespace pushmi {
  20. namespace detail {
  21. struct no_fail_fn {
  22. private:
  23. struct on_error_impl {
  24. [[noreturn]] void operator()(any, any) noexcept {
  25. std::abort();
  26. }
  27. };
  28. template <class In>
  29. struct out_impl {
  30. PUSHMI_TEMPLATE(class Out)
  31. (requires Receiver<Out>)auto operator()(Out out) const {
  32. return ::pushmi::detail::receiver_from_fn<In>()(
  33. std::move(out), ::pushmi::on_error(on_error_impl{}));
  34. }
  35. };
  36. struct in_impl {
  37. PUSHMI_TEMPLATE(class In)
  38. (requires Sender<In>)auto operator()(In in) const {
  39. return ::pushmi::detail::sender_from(
  40. std::move(in),
  41. ::pushmi::detail::submit_transform_out<In>(out_impl<In>{}));
  42. }
  43. };
  44. public:
  45. auto operator()() const {
  46. return in_impl{};
  47. }
  48. };
  49. } // namespace detail
  50. namespace operators {
  51. PUSHMI_INLINE_VAR constexpr detail::no_fail_fn no_fail{};
  52. } // namespace operators
  53. } // namespace pushmi