1

I wish to make an extension function that doesn't care about the type of observable it receives.

For example:

template <typename T>
inline auto makeones() -> function<observable<int>(observable<T>)>
{
return [=](observable<T> s) {
    return s | rxo::map([=](auto x) { return 1; }) 
};
}

I would like to be able to call this method without specifying the template if possible.

For example:

stream | makeones() 

as opposed to

stream | makeones<myType>()

I suppose this is more of a c++ question than an rxcpp question. Is this possible to do?

jc211
  • 397
  • 2
  • 9
  • As long as I know and I had this question about **template** you **cannot** have a template with no `<>` With some specialization you can use `class<>` and so on, but you cannot use it without `<>`. Of course if you have a fixed input, you can use `typedef` like any class in `std` for example `std::string` is: `std::basic_string` with typedef – Shakiba Moshiri Jul 27 '17 at 13:13

1 Answers1

1

You can use a struct with a template method:

struct makeones {
  template <typename Observable>
  inline observable<int> operator()(Observable s) {
    return s | rxo::map([=](typename Observable::value_type x) { return 1; });
  }
};
maiermic
  • 4,764
  • 6
  • 38
  • 77