mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
8ffcd49dd2
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.
20 lines
371 B
C++
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
|