async_for.hpp 652 B

1234567891011121314151617
  1. // Copyright (c) 2023 Klemens D. Morgenstern
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_COBALT_COBALT_FOR_HPP
  6. #define BOOST_COBALT_COBALT_FOR_HPP
  7. #include <boost/preprocessor/cat.hpp>
  8. #define BOOST_COBALT_FOR_IMPL(Value, Expression, Id) \
  9. for (auto && Id = Expression; Id; ) \
  10. if (Value = co_await Id; false) {} else
  11. #define BOOST_COBALT_FOR(Value, Expression) \
  12. BOOST_COBALT_FOR_IMPL(Value, Expression, BOOST_PP_CAT(__boost_cobalt_for_loop_value__, __LINE__))
  13. #endif //BOOST_COBALT_COBALT_FOR_HPP