Files
revng-revng/include/revng/ADT/RecursiveCoroutine-fallback.h
Pietro Fezzardi 8ffcd49dd2 RecursiveCoroutine: fix reference arguments
Before this commit, recursive coroutines did not work properly if they
had out arguments with reference type.
The reason is that `rc_run` was inferring the type of its arguments from
the arguments themselves, not from the prototype of the recursive
coroutine.

Hence, code snippets like the following did not work properly, because
`rc_run` was taking x by value, not by reference.

```
RecursiveCoroutine<void> accumulate_on_i(int &i) {
  // ...
}

int f() {
  int x = 0;
  rc_run(accumulate_on_i, x);
  return x;
}
```

This commit fixes the problem. Now the arguments of `rc_run` are
properly forwarded to the recursive coroutine.
2021-02-17 11:37:00 +01:00

20 lines
371 B
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include <utility>
template<typename ReturnT = void>
using RecursiveCoroutine = ReturnT;
template<typename CoroutineT, typename... Args>
auto rc_run(CoroutineT F, Args &&... args) {
return F(std::forward<Args>(args)...);
}
#define rc_return return
#define rc_recur