Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting connectable_observable* to observable* #376

Open
martinfinke opened this issue May 14, 2017 · 1 comment
Open

Converting connectable_observable* to observable* #376

martinfinke opened this issue May 14, 2017 · 1 comment
Labels

Comments

@martinfinke
Copy link

Please consider this example:

// 1: This compiles
rxcpp::connectable_observable<int> connectable;
rxcpp::observable<int> o = connectable;

// 2: This doesn't
rxcpp::connectable_observable<int> *connectable_ptr;
rxcpp::observable<int> *ptr = connectable_ptr;

Since connectable_observable derives from observable, why does (1) compile, and (2) doesn't?

@kirkshoop
Copy link
Member

kirkshoop commented May 23, 2017

Yes, connectable_observable<> does inherit from observable<>

template<class T, class SourceOperator>
class connectable_observable
    : public observable<T, SourceOperator>

The devil is in the type-forgetting of the SourceOperator.

template<
    class T = void,
    class SourceObservable = typename std::conditional<std::is_same<T, void>::value,
        void, dynamic_observable<T>>::type>
class observable;

template<class T,
    class SourceObservable = typename std::conditional<std::is_same<T, void>::value,
        void, dynamic_connectable_observable<T>>::type>
class connectable_observable;

So connectable_observable<int> is actually

class connectable_observable<int, dynamic_connectable_observable<int>>
    : public observable<int, dynamic_connectable_observable<int>>

which does not convert to observable<int, dynamic_observable<int>>

This is surprising behavior and we should think about how to make the type-forgetting work with this cast to the base.

Thanks for the report!

@kirkshoop kirkshoop added the bug label Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants