ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.03k stars 390 forks source link

Error when creating observer from functor instance? #541

Closed serg06 closed 4 years ago

serg06 commented 4 years ago

Hey guys, I'm trying to create an observable from a functor and I get an error:

class ObserverWrapper
{
public:
    void operator()(rxcpp::subscriber<int> s)
    {
        s.on_completed();
    }
};

int main()
{
    auto functor = ObserverWrapper();
    auto ints = rxcpp::observable<>::create<int>(functor);
}

Is that something I'm allowed to do?

Also, I noticed that if I cast it as an std::function first, the error goes away:

int main()
{
    auto functor = ObserverWrapper();
    auto casted = static_cast<std::function<void(rxcpp::subscriber<int> s)>>(functor);
    auto ints = rxcpp::observable<>::create<int>(casted);
}

Is this a bug or expected behaviour?