question

16820936 avatar image
0 Votes"
16820936 asked ·

C + + function pointer parameter pass error


















include <iostream>

include <thread>

include<coroutine>

include<string>

include<concepts>

include <experimental/coroutine>

using namespace std;
using namespace std::experimental;

include <iostream>

include <coroutine>

template<class T, class...V>
auto Register();
template<class T>
struct generator
{
struct promise_type;
using handle = coroutine_handle<promise_type>;
struct promise_type
{
T current_value;
static auto get_return_object_on_allocation_failure() { return generator<T>{ nullptr }; }
auto get_return_object() { return generator<T>{ handle::from_promise(*this) }; }
auto initial_suspend() { return suspend_always{}; }
auto final_suspend() { return suspend_always{}; }
void unhandled_exception() { std::terminate(); }
void return_void() {}

     auto yield_value(T value)
     {
         current_value = value;
         return suspend_always{}; // 这是一个 awaiter 结构, 见第二篇文章
     }
 };
 bool move_next() { return coro ? (coro.resume(), !coro.done()) : false; };
 T current_value() {
     if (move_next()) {
         return coro.promise().current_value;
     }
 }
 generator(generator<T>&) = delete;
 generator(generator<T>&& rhs) : coro(rhs.coro) { rhs.coro = nullptr; }
 ~generator<T>()
 {
     if (coro)
         coro.destroy();
 }

public:
handle coro;
generator<T>(handle h) : coro(h) {};

};
template<class T,class...A>
generator<T>(*List)(T t, A...a);

define Coroutine generator

template<class T>
generator<T> f()
{
co_yield "Hi";
}
namespace Fine {
int i = 0;
}
//TODO : 写入代码
Coroutine<int>Function(int,int) {
co_yield 90;
}




int main() {
List<int, int>(12, 34);//Throw an exception
}

c++
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Do you have a better sample code that can be compiled and tested? If you edit the question, you can use the “101” button to paste the code. Also show the exception details.

0 Votes 0 ·

0 Answers