20 #if !defined(RXCPP_OPERATORS_RX_SWITCH_IF_EMPTY_HPP) 21 #define RXCPP_OPERATORS_RX_SWITCH_IF_EMPTY_HPP 23 #include "../rx-includes.hpp" 32 struct switch_if_empty_invalid_arguments {};
35 struct switch_if_empty_invalid :
public rxo::operator_base<switch_if_empty_invalid_arguments<AN...>> {
36 using type = observable<switch_if_empty_invalid_arguments<
AN...>, switch_if_empty_invalid<
AN...>>;
39 using switch_if_empty_invalid_t =
typename switch_if_empty_invalid<
AN...>::type;
41 template<
class T,
class BackupSource>
44 typedef rxu::decay_t<T> source_value_type;
45 typedef rxu::decay_t<BackupSource> backup_source_type;
47 backup_source_type backup;
50 : backup(std::move(b))
54 template<
class Subscriber>
55 struct switch_if_empty_observer
57 typedef switch_if_empty_observer<Subscriber> this_type;
58 typedef source_value_type value_type;
59 typedef rxu::decay_t<Subscriber> dest_type;
60 typedef observer<value_type, this_type> observer_type;
63 composite_subscription lifetime;
64 backup_source_type backup;
67 switch_if_empty_observer(dest_type d, composite_subscription cs, backup_source_type b)
69 , lifetime(std::move(cs))
70 , backup(std::move(b))
75 void on_next(source_value_type v)
const {
77 dest.on_next(std::move(v));
79 void on_error(std::exception_ptr e)
const {
80 dest.on_error(std::move(e));
82 void on_completed()
const {
86 backup.subscribe(dest);
90 static subscriber<value_type, observer_type> make(dest_type d, backup_source_type b) {
91 auto cs = composite_subscription();
92 return make_subscriber<value_type>(cs, observer_type(this_type(std::move(d), cs, std::move(b))));
96 template<
class Subscriber>
97 auto operator()(Subscriber dest)
const 98 -> decltype(switch_if_empty_observer<Subscriber>::make(std::move(dest), std::move(backup))) {
99 return switch_if_empty_observer<Subscriber>::make(std::move(dest), std::move(backup));
107 template<
class...
AN>
110 return operator_factory<switch_if_empty_tag,
AN...>(std::make_tuple(std::forward<AN>(an)...));
125 template<
class...
AN>
128 return operator_factory<default_if_empty_tag,
AN...>(std::make_tuple(std::forward<AN>(an)...));
136 template<
class Observable,
class BackupSource,
140 class SwitchIfEmpty = rxo::detail::switch_if_empty<SourceValue, rxu::decay_t<BackupSource>>>
141 static auto member(Observable&& o, BackupSource&& b)
142 -> decltype(o.template lift<SourceValue>(SwitchIfEmpty(std::forward<BackupSource>(b)))) {
143 return o.template lift<SourceValue>(SwitchIfEmpty(std::forward<BackupSource>(b)));
146 template<
class...
AN>
147 static operators::detail::switch_if_empty_invalid_t<
AN...>
member(
AN...) {
150 static_assert(
sizeof...(
AN) == 10000,
"switch_if_empty takes (BackupSource)");
157 template<
class Observable,
class Value,
161 class BackupSource = decltype(
rxs::from(std::declval<SourceValue>())),
162 class DefaultIfEmpty = rxo::detail::switch_if_empty<SourceValue, BackupSource>>
163 static auto member(Observable&& o, Value v)
164 -> decltype(o.template lift<SourceValue>(DefaultIfEmpty(
rxs::from(std::move(v))))) {
165 return o.template lift<SourceValue>(DefaultIfEmpty(
rxs::from(std::move(v))));
168 template<
class...
AN>
169 static operators::detail::switch_if_empty_invalid_t<
AN...>
member(
AN...) {
172 static_assert(
sizeof...(
AN) == 10000,
"default_if_empty takes (Value)");
auto default_if_empty(AN &&...an) -> operator_factory< default_if_empty_tag, AN... >
If the source Observable terminates without emitting any items, emits a default item and completes...
Definition: rx-switch_if_empty.hpp:126
Definition: rx-util.hpp:100
Definition: rx-all.hpp:26
typename std::decay< T >::type::value_type value_type_t
Definition: rx-util.hpp:35
static operators::detail::switch_if_empty_invalid_t< AN... > member(AN...)
Definition: rx-switch_if_empty.hpp:169
Definition: rx-operators.hpp:69
Definition: rx-operators.hpp:408
auto AN
Definition: rx-finally.hpp:105
static auto member(Observable &&o, BackupSource &&b) -> decltype(o.template lift< SourceValue >(SwitchIfEmpty(std::forward< BackupSource >(b))))
Definition: rx-switch_if_empty.hpp:141
Definition: rx-operators.hpp:47
linq_driver< iter_cursor< typename util::container_traits< TContainer >::iterator > > from(TContainer &c)
Definition: linq.hpp:556
auto is_empty(AN &&...an) -> operator_factory< is_empty_tag, AN... >
Returns an Observable that emits true if the source Observable is empty, otherwise false...
Definition: rx-all.hpp:128
typename std::enable_if< all_true_type< BN... >::value >::type enable_if_all_true_type_t
Definition: rx-util.hpp:114
static operators::detail::switch_if_empty_invalid_t< AN... > member(AN...)
Definition: rx-switch_if_empty.hpp:147
static auto member(Observable &&o, Value v) -> decltype(o.template lift< SourceValue >(DefaultIfEmpty(rxs::from(std::move(v)))))
Definition: rx-switch_if_empty.hpp:163
auto switch_if_empty(AN &&...an) -> operator_factory< switch_if_empty_tag, AN... >
If the source Observable terminates without emitting any items, emits items from a backup Observable...
Definition: rx-switch_if_empty.hpp:108
Definition: rx-operators.hpp:402
Definition: rx-predef.hpp:177