From 06fbdc7419506a46e9b0bdaa27800da9615e53ce Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 17 Mar 2017 02:45:49 +0100 Subject: [PATCH] remove coroutine_type, but keep public context --- examples/coroutine2.cc | 8 ++++---- ostd/coroutine.hh | 8 -------- ostd/internal/context.hh | 18 ------------------ 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/examples/coroutine2.cc b/examples/coroutine2.cc index 4937463..b8eb29e 100644 --- a/examples/coroutine2.cc +++ b/examples/coroutine2.cc @@ -17,18 +17,18 @@ int main() { generator x{f}; /* coroutine_context exists as a base type for any coroutine */ - coroutine_context &ctx = x; + coroutine_context *ctx = &x; writefln( "generator is coroutine: %s", - bool(ctx.coroutine>()) + bool(dynamic_cast *>(ctx)) ); writefln( "generator is generator: %s", - bool(ctx.coroutine>()) + bool(dynamic_cast *>(ctx)) ); - generator &gr = *ctx.coroutine>(); + generator &gr = dynamic_cast &>(*ctx); writefln("value of cast back generator: %s", gr.value()); } diff --git a/ostd/coroutine.hh b/ostd/coroutine.hh index 1370bab..142ce73 100644 --- a/ostd/coroutine.hh +++ b/ostd/coroutine.hh @@ -399,10 +399,6 @@ public: template 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 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}); diff --git a/ostd/internal/context.hh b/ostd/internal/context.hh index 7a8bff3..d081cd1 100644 --- a/ostd/internal/context.hh +++ b/ostd/internal/context.hh @@ -43,24 +43,6 @@ namespace detail { } /* namespace detail */ struct coroutine_context { - virtual std::type_info const &coroutine_type() const = 0; - - template - T *coroutine() { - if (coroutine_type() == typeid(T)) { - return reinterpret_cast(this); - } - return nullptr; - } - - template - T const *coroutine() const { - if (coroutine_type() == typeid(T)) { - return reinterpret_cast(this); - } - return nullptr; - } - protected: coroutine_context() {} ~coroutine_context() {