Skip to content

Commit

Permalink
Use old namespace macro
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTF committed Dec 1, 2021
1 parent 0354673 commit 0a8daee
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/util/streamable_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
#include <exception>
#include <sstream>

// coroutines are still experimental in clang, adapt the appropriate namespaces.
// coroutines are still experimental in clang, adapt the appropriate
// namespaces.
#ifdef __clang__
#include <experimental/coroutine>
namespace qlever_stdOrExp = std::experimental;
#else
#include <coroutine>
namespace qlever_stdOrExp = std;
#endif

namespace ad_utility::stream_generator {

// coroutines are still experimental in clang, adapt the appropriate namespaces.
#ifdef __clang__
using std::suspend_always = std::experimental::suspend_always;
using std::suspend_never = std::experimental::suspend_never;
using std::coroutine_handle = std::experimental::coroutine_handle;
#endif

template <typename T>
concept Streamable = requires(T x, std::ostream& os) {
os << x;
Expand All @@ -33,7 +29,8 @@ class suspend_sometimes {
public:
explicit suspend_sometimes(const bool suspend) : suspend(suspend) {}
bool await_ready() const noexcept { return !suspend; }
constexpr void await_suspend(std::coroutine_handle<>) const noexcept {}
constexpr void await_suspend(
qlever_stdOrExp::coroutine_handle<>) const noexcept {}
constexpr void await_resume() const noexcept {}
};

Expand All @@ -47,8 +44,12 @@ class stream_generator_promise {

stream_generator get_return_object() noexcept;

constexpr std::suspend_always initial_suspend() const noexcept { return {}; }
constexpr std::suspend_always final_suspend() const noexcept { return {}; }
constexpr qlever_stdOrExp::suspend_always initial_suspend() const noexcept {
return {};
}
constexpr qlever_stdOrExp::suspend_always final_suspend() const noexcept {
return {};
}

template <Streamable T>
suspend_sometimes yield_value(T&& value) noexcept {
Expand All @@ -75,7 +76,7 @@ class stream_generator_promise {

// Don't allow any use of 'co_await' inside the generator coroutine.
template <typename U>
std::suspend_never await_transform(U&& value) = delete;
qlever_stdOrExp::suspend_never await_transform(U&& value) = delete;

void rethrow_if_exception() {
if (m_exception) {
Expand Down Expand Up @@ -139,15 +140,16 @@ class [[nodiscard]] stream_generator {
friend class detail::stream_generator_promise;

explicit stream_generator(
std::coroutine_handle<promise_type> coroutine) noexcept
qlever_stdOrExp::coroutine_handle<promise_type> coroutine) noexcept
: m_coroutine(coroutine) {}

std::coroutine_handle<promise_type> m_coroutine;
qlever_stdOrExp::coroutine_handle<promise_type> m_coroutine;
};

namespace detail {
inline stream_generator stream_generator_promise::get_return_object() noexcept {
using coroutine_handle = std::coroutine_handle<stream_generator_promise>;
using coroutine_handle =
qlever_stdOrExp::coroutine_handle<stream_generator_promise>;
return stream_generator{coroutine_handle::from_promise(*this)};
}
} // namespace detail
Expand Down

0 comments on commit 0a8daee

Please sign in to comment.