remove coroutine_type, but keep public context

master
Daniel Kolesa 2017-03-17 02:45:49 +01:00
parent c7451024c7
commit 06fbdc7419
3 changed files with 4 additions and 30 deletions

View File

@ -17,18 +17,18 @@ int main() {
generator<int> x{f}; generator<int> x{f};
/* coroutine_context exists as a base type for any coroutine */ /* coroutine_context exists as a base type for any coroutine */
coroutine_context &ctx = x; coroutine_context *ctx = &x;
writefln( writefln(
"generator is coroutine<int()>: %s", "generator is coroutine<int()>: %s",
bool(ctx.coroutine<coroutine<int()>>()) bool(dynamic_cast<coroutine<int()> *>(ctx))
); );
writefln( writefln(
"generator is generator<int>: %s", "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()); writefln("value of cast back generator: %s", gr.value());
} }

View File

@ -399,10 +399,6 @@ public:
template<typename F> template<typename F>
F const *target() const { return p_stor.p_func.target(); } F const *target() const { return p_stor.p_func.target(); }
std::type_info const &coroutine_type() const {
return typeid(coroutine);
}
private: private:
void resume_call() { void resume_call() {
p_stor.call_helper(*this); p_stor.call_helper(*this);
@ -572,10 +568,6 @@ public:
template<typename F> template<typename F>
F const *target() const { return p_func.target(); } F const *target() const { return p_func.target(); }
std::type_info const &coroutine_type() const {
return typeid(generator);
}
private: private:
void resume_call() { void resume_call() {
p_func(yield_type{*this}); p_func(yield_type{*this});

View File

@ -43,24 +43,6 @@ namespace detail {
} /* namespace detail */ } /* namespace detail */
struct coroutine_context { 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: protected:
coroutine_context() {} coroutine_context() {}
~coroutine_context() { ~coroutine_context() {