Closed victimsnino closed 2 years ago
@kirkshoop , moved discussion to this thread as requested
One option is to make the virtual function implementations forward to non-virtual internal functions that use enable-if to prune the branches that are invalid and 'magic' the ones that are invalid - const T&
-> T&
would make a copy, but would prefer a T&&
overload of the destination on_next over a T&
overload.
Another approach is to make the exact type of T supplied to the virtual_observer the only virtual overload for on_next and fail at compile time if the observer passed to the virtual_observer
I prefer the second option.
@kirkshoop, To clarify idea: Do you want to make type deduction/usage more strict? for example,
auto root = rxcpp::observable<>::just(1); // observable<int>;
auto modified = root.map([](int& v){v += 1; return v;}); // observable<int>, but internal observer int&. compilable due to int convetible to int& . Modifies original value inside "just" in this case or just sends copy everytime?
auto ref_modified = modified.map([](int& v)-> int& {return v;}); // observable<int&> Observer int&.
ref_modified.map([](int v){}); // copy of int&
auto const_ref_modified = modified.map([](int& v)-> const int& {return v;}); // observable<const int&>
const_ref_modified.map([](int& v){}); // non compilable due to const int& non-convertible to int&
and etc?
Do you want to make type deduction/usage more strict?
@victimsnino, yep, those examples look good to me
To continue thread from #562 .
I've tried to provide override
T&
for on_next. From the point of actual execution it works as expected, but compiler tries to satisfy all possible (and unused) ways of execution (for example, constT& to T&). Can we solve it?