@@ -38,9 +38,15 @@ class Events : public REACT_IMPL::EventStreamBase<D,E>
3838 using NodePtrT = REACT_IMPL::SharedPtrT<NodeT>;
3939
4040public:
41+ using ValueT = E;
42+
4143 Events () = default ;
4244 Events (const Events&) = default ;
4345
46+ Events (Events&& other) :
47+ EventStreamBase{ std::move (other) }
48+ {}
49+
4450 explicit Events (NodePtrT&& nodePtr) :
4551 EventStreamBase{ std::move (nodePtr) }
4652 {}
@@ -64,19 +70,53 @@ class Events : public REACT_IMPL::EventStreamBase<D,E>
6470 }
6571};
6672
67- /* *****************************************/ REACT_END /* *****************************************/
73+ // Specialize for references
74+ template
75+ <
76+ typename D,
77+ typename E
78+ >
79+ class Events <D,E&> : public REACT_IMPL::EventStreamBase<D,std::reference_wrapper<E>>
80+ {
81+ protected:
82+ using BaseT = REACT_IMPL::EventStreamBase<D,std::reference_wrapper<E>>;
6883
69- /* **************************************/ REACT_IMPL_BEGIN /* *************************************/
84+ private:
85+ using NodeT = REACT_IMPL::EventStreamNode<D,std::reference_wrapper<E>>;
86+ using NodePtrT = REACT_IMPL::SharedPtrT<NodeT>;
7087
71- template <typename D, typename L, typename R>
72- bool Equals (const Events<D,L>& lhs, const Events<D,R>& rhs)
73- {
74- return lhs.Equals (rhs);
75- }
88+ public:
89+ using ValueT = std::reference_wrapper<E>;
7690
77- /* ***************************************/ REACT_IMPL_END /* **************************************/
91+ Events () = default ;
92+ Events (const Events&) = default ;
7893
79- /* ****************************************/ REACT_BEGIN /* ****************************************/
94+ Events (Events&& other) :
95+ EventStreamBase{ std::move (other) }
96+ {}
97+
98+ explicit Events (NodePtrT&& nodePtr) :
99+ EventStreamBase{ std::move (nodePtr) }
100+ {}
101+
102+ template <typename F>
103+ Events Filter (F&& f)
104+ {
105+ return REACT::Filter (*this , std::forward<F>(f));
106+ }
107+
108+ template <typename F>
109+ Events Transform (F&& f)
110+ {
111+ return REACT::Transform (*this , std::forward<F>(f));
112+ }
113+
114+ template <typename F>
115+ Observer<D> Observe (F&& f)
116+ {
117+ return REACT::Observe (*this , std::forward<F>(f));
118+ }
119+ };
80120
81121// /////////////////////////////////////////////////////////////////////////////////////////////////
82122// / EventSource
@@ -93,11 +133,13 @@ class EventSource : public Events<D,E>
93133 using NodePtrT = REACT_IMPL::SharedPtrT<NodeT>;
94134
95135public:
96- using ValueT = E;
97-
98136 EventSource () = default ;
99137 EventSource (const EventSource&) = default ;
100138
139+ EventSource (EventSource&& other) :
140+ Events{ std::move (other) }
141+ {}
142+
101143 explicit EventSource (NodePtrT&& nodePtr) :
102144 Events{ std::move (nodePtr) }
103145 {}
@@ -122,6 +164,43 @@ class EventSource : public Events<D,E>
122164 }
123165};
124166
167+ // Specialize for references
168+ template
169+ <
170+ typename D,
171+ typename E
172+ >
173+ class EventSource <D,E&> : public Events<D,std::reference_wrapper<E>>
174+ {
175+ private:
176+ using NodeT = REACT_IMPL::EventSourceNode<D,std::reference_wrapper<E>>;
177+ using NodePtrT = REACT_IMPL::SharedPtrT<NodeT>;
178+
179+ public:
180+ EventSource () = default ;
181+ EventSource (const EventSource&) = default ;
182+
183+ EventSource (EventSource&& other) :
184+ Events{ std::move (other) }
185+ {}
186+
187+ explicit EventSource (NodePtrT&& nodePtr) :
188+ Events{ std::move (nodePtr) }
189+ {}
190+
191+ void Emit (std::reference_wrapper<E> e) const
192+ {
193+ BaseT::emit (e);
194+ }
195+
196+ template <typename T>
197+ const EventSource& operator <<(std::reference_wrapper<E> e) const
198+ {
199+ BaseT::emit (e);
200+ return *this ;
201+ }
202+ };
203+
125204// /////////////////////////////////////////////////////////////////////////////////////////////////
126205// / TempEvents
127206// /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -141,6 +220,10 @@ class TempEvents : public Events<D,E>
141220 TempEvents () = default ;
142221 TempEvents (const TempEvents&) = default ;
143222
223+ TempEvents (TempEvents&& other) :
224+ Events{ std::move (other) }
225+ {}
226+
144227 explicit TempEvents (NodePtrT&& nodePtr) :
145228 Events{ std::move (nodePtr) }
146229 {}
@@ -151,6 +234,20 @@ class TempEvents : public Events<D,E>
151234 }
152235};
153236
237+ /* *****************************************/ REACT_END /* *****************************************/
238+
239+ /* **************************************/ REACT_IMPL_BEGIN /* *************************************/
240+
241+ template <typename D, typename L, typename R>
242+ bool Equals (const Events<D,L>& lhs, const Events<D,R>& rhs)
243+ {
244+ return lhs.Equals (rhs);
245+ }
246+
247+ /* ***************************************/ REACT_IMPL_END /* **************************************/
248+
249+ /* ****************************************/ REACT_BEGIN /* ****************************************/
250+
154251// /////////////////////////////////////////////////////////////////////////////////////////////////
155252// / MakeEventSource
156253// /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -191,7 +288,7 @@ auto Merge(const Events<D,TArg1>& arg1, const Events<D,TArgs>& ... args)
191288
192289 return TempEvents<D,E,TOp>(
193290 std::make_shared<REACT_IMPL::EventOpNode<D,E,TOp>>(
194- arg1.GetPtr (), args.GetPtr () ...));
291+ arg1.NodePtr (), args.NodePtr () ...));
195292}
196293
197294template
@@ -215,7 +312,7 @@ auto operator|(const TLeftEvents& lhs, const TRightEvents& rhs)
215312{
216313 return TempEvents<D,E,TOp>(
217314 std::make_shared<REACT_IMPL::EventOpNode<D,E,TOp>>(
218- lhs.GetPtr (), rhs.GetPtr ()));
315+ lhs.NodePtr (), rhs.NodePtr ()));
219316}
220317
221318template
@@ -255,7 +352,7 @@ auto operator|(TempEvents<D,TLeftVal,TLeftOp>&& lhs, const TRightEvents& rhs)
255352{
256353 return TempEvents<D,E,TOp>(
257354 std::make_shared<REACT_IMPL::EventOpNode<D,E,TOp>>(
258- lhs.StealOp (), rhs.GetPtr ()));
355+ lhs.StealOp (), rhs.NodePtr ()));
259356}
260357
261358template
@@ -277,7 +374,7 @@ auto operator|(const TLeftEvents& lhs, TempEvents<D,TRightVal,TRightOp>&& rhs)
277374{
278375 return TempEvents<D,E,TOp>(
279376 std::make_shared<REACT_IMPL::EventOpNode<D,E,TOp>>(
280- lhs.GetPtr (), rhs.StealOp ()));
377+ lhs.NodePtr (), rhs.StealOp ()));
281378}
282379
283380// /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -297,7 +394,7 @@ auto Filter(const Events<D,E>& src, FIn&& filter)
297394{
298395 return TempEvents<D,E,TOp>(
299396 std::make_shared<REACT_IMPL::EventOpNode<D,E,TOp>>(
300- std::forward<FIn>(filter), src.GetPtr ()));
397+ std::forward<FIn>(filter), src.NodePtr ()));
301398}
302399
303400template
@@ -347,7 +444,7 @@ auto Transform(const Events<D,E>& src, FIn&& func)
347444{
348445 return TempEvents<D,E,TOp>(
349446 std::make_shared<REACT_IMPL::EventOpNode<D,E,TOp>>(
350- std::forward<FIn>(func), src.GetPtr ()));
447+ std::forward<FIn>(func), src.NodePtr ()));
351448}
352449
353450template
@@ -393,7 +490,7 @@ auto Flatten(const Signal<D,Events<D,TInnerValue>>& node)
393490{
394491 return Events<D,TInnerValue>(
395492 std::make_shared<REACT_IMPL::EventFlattenNode<D, Events<D,TInnerValue>, TInnerValue>>(
396- node.GetPtr (), node ().GetPtr ()));
493+ node.NodePtr (), node ().NodePtr ()));
397494}
398495
399496// /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -416,7 +513,7 @@ auto Observe(const Events<D,TArg>& subject, FIn&& func)
416513 auto * raw = REACT_IMPL::DomainSpecificObserverRegistry<D>::Instance ().
417514 template Register<TNode>(subject, std::forward<FIn>(func));
418515
419- return Observer<D>(raw, subject.GetPtr ());
516+ return Observer<D>(raw, subject.NodePtr ());
420517}
421518
422519template
@@ -434,7 +531,7 @@ auto Observe(const Events<D,EventToken>& subject, FIn&& func)
434531 auto * raw = REACT_IMPL::DomainSpecificObserverRegistry<D>::Instance ().
435532 template Register<TNode>(subject, std::move (wrapper));
436533
437- return Observer<D>(raw, subject.GetPtr ());
534+ return Observer<D>(raw, subject.NodePtr ());
438535}
439536
440537/* *****************************************/ REACT_END /* *****************************************/
0 commit comments