remove coroutine_type, but keep public context
parent
c7451024c7
commit
06fbdc7419
|
@ -17,18 +17,18 @@ int main() {
|
|||
|
||||
generator<int> x{f};
|
||||
/* coroutine_context exists as a base type for any coroutine */
|
||||
coroutine_context &ctx = x;
|
||||
coroutine_context *ctx = &x;
|
||||
|
||||
writefln(
|
||||
"generator is coroutine<int()>: %s",
|
||||
bool(ctx.coroutine<coroutine<int()>>())
|
||||
bool(dynamic_cast<coroutine<int()> *>(ctx))
|
||||
);
|
||||
writefln(
|
||||
"generator is generator<int>: %s",
|
||||
bool(ctx.coroutine<generator<int>>())
|
||||
bool(dynamic_cast<generator<int> *>(ctx))
|
||||
);
|
||||
|
||||
generator<int> &gr = *ctx.coroutine<generator<int>>();
|
||||
generator<int> &gr = dynamic_cast<generator<int> &>(*ctx);
|
||||
writefln("value of cast back generator: %s", gr.value());
|
||||
}
|
||||
|
||||
|
|
|
@ -399,10 +399,6 @@ public:
|
|||
template<typename F>
|
||||
F const *target() const { return p_stor.p_func.target(); }
|
||||
|
||||
std::type_info const &coroutine_type() const {
|
||||
return typeid(coroutine);
|
||||
}
|
||||
|
||||
private:
|
||||
void resume_call() {
|
||||
p_stor.call_helper(*this);
|
||||
|
@ -572,10 +568,6 @@ public:
|
|||
template<typename F>
|
||||
F const *target() const { return p_func.target(); }
|
||||
|
||||
std::type_info const &coroutine_type() const {
|
||||
return typeid(generator);
|
||||
}
|
||||
|
||||
private:
|
||||
void resume_call() {
|
||||
p_func(yield_type{*this});
|
||||
|
|
|
@ -43,24 +43,6 @@ namespace detail {
|
|||
} /* namespace detail */
|
||||
|
||||
struct coroutine_context {
|
||||
virtual std::type_info const &coroutine_type() const = 0;
|
||||
|
||||
template<typename T>
|
||||
T *coroutine() {
|
||||
if (coroutine_type() == typeid(T)) {
|
||||
return reinterpret_cast<T *>(this);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T const *coroutine() const {
|
||||
if (coroutine_type() == typeid(T)) {
|
||||
return reinterpret_cast<T const *>(this);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
coroutine_context() {}
|
||||
~coroutine_context() {
|
||||
|
|
Loading…
Reference in New Issue