3

I program with RX in C#, and now I wish to program with rxcpp in c++. I am trying to do the simplest thing, define a class member variable of observable<int>.
The problem is that observable is defined as:

template<class T, class SourceOperator>
class observable

What is SourceOperator?
How do I define a simple observable<int>?

When looking in the code, at rx-observable.hpp(line 101):

template<class T, class Source>
observable<T> make_observable_dynamic(Source&& s) {
   return observable<T>(dynamic_observable<T>(std::forward<Source>(s)));
}

I find observale<T> as a return type, but couldn't find its definition.
It so weird. I honestly though I am quite proficient in c++11\14 & Metaprogramming... apparently the rabbit hole can get much deeper :-(

Update 1:
observale<T> has been found :-) its in rx-predef.hpp:

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

o.k. my current guess is that dynamic_observable means that a 'regular' observable<T>is a dynamic, type-ereased stream of T. It's logical, as you can only sotre type-erased stream as a variable with an explicit type.
What brings me to my next guess, that the syntax of template<class T, class SourceOperator> class observable enable the creation of observable type combined from other observable in the 'decorator' pattern (compile time decoration). something like exemplified here

Community
  • 1
  • 1
ShaulF
  • 841
  • 10
  • 17
  • That's weird. The example on the [github](https://github.com/Reactive-Extensions/RxCpp) page defines several variables without specifying `SourceOperator`: `observable` and `observable`. – Rakete1111 Feb 26 '17 at 14:51
  • The documentation of this thing really sucks. http://reactive-extensions.github.io/RxCpp/classrxcpp_1_1observable.html#details uses `SourceOperator` all over the place without explaining what it means. Definitely not something I'd use outside of private toy projects. – Christian Hackl Feb 26 '17 at 14:56
  • 1
    Yes, update 1 is correct! In c++ the default is to let the compiler see the complete static type and collapse all the operators together for performance. SourceOperator is the complete type of the observable held by the generic observable type. The as_dynamic() method on an observable will return the type-erased observable this imposes virtual function call overhead and heap allocation overhead that the default avoids. – Kirk Shoop Feb 26 '17 at 20:24
  • 1
    @ChristianHackl all contributions are welcome - especially documentation improvements. Even adding an issue for the topics that you need covered in order to trust rxcpp would be valuable. – Kirk Shoop Feb 26 '17 at 20:25

1 Answers1

1

observale<T> has been found :-) its in rx-predef.hpp:

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

dynamic_observable means a observable<T> which is a dynamic, type-ereased stream of T. It's logical, as you can only sotre type-erased stream as a variable with an explicit type.
The syntax of template<class T, class SourceOperator> class observable enable the creation of observable type combined from other observable in the 'decorator' pattern (compile time decoration). something like exemplified here

ShaulF
  • 841
  • 10
  • 17