Skip to content

Commit 860e344

Browse files
committed
Using ->* for function bind rather than >>=.
Revisited InputPack code, using proper types now.
1 parent dfa7cb8 commit 860e344

9 files changed

Lines changed: 53 additions & 55 deletions

File tree

include/react/Signal.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -481,17 +481,17 @@ template
481481
>
482482
struct InputPack
483483
{
484-
std::tuple<RSignal<D, TValues> ...> Data;
484+
std::tuple<const RSignal<D, TValues>& ...> Data;
485485

486486
template <typename TFirstValue, typename TSecondValue>
487487
InputPack(const RSignal<D,TFirstValue>& first, const RSignal<D,TSecondValue>& second) :
488-
Data(std::make_tuple(first, second))
488+
Data(std::tie(first, second))
489489
{
490490
}
491491

492492
template <typename ... TCurValues, typename TAppendValue>
493493
InputPack(const InputPack<D, TCurValues ...>& curArgs, const RSignal<D,TAppendValue>& newArg) :
494-
Data(std::tuple_cat(curArgs.Data, std::make_tuple(newArg)))
494+
Data(std::tuple_cat(curArgs.Data, std::tie(newArg)))
495495
{
496496
}
497497
};
@@ -533,15 +533,15 @@ REACT_IMPL_BEGIN
533533
template
534534
<
535535
typename D,
536-
typename TFunc,
536+
typename F,
537537
typename ... TValues
538538
>
539539
struct ApplyHelper
540540
{
541-
static inline auto MakeSignal(const TFunc& func, const RSignal<D,TValues>& ... args)
542-
-> decltype(D::MakeSignal(func, args ...))
541+
static inline auto MakeSignal(F&& func, const RSignal<D,TValues>& ... args)
542+
-> decltype(D::MakeSignal(std::forward<F>(func), args ...))
543543
{
544-
return D::MakeSignal(func, args ...);
544+
return D::MakeSignal(std::forward<F>(func), args ...);
545545
}
546546
};
547547

@@ -550,34 +550,34 @@ REACT_IMPL_END
550550
REACT_BEGIN
551551

552552
////////////////////////////////////////////////////////////////////////////////////////
553-
/// operator>>= overload to connect inputs to a function and return the resulting node.
553+
/// operator->* overload to connect inputs to a function and return the resulting node.
554554
////////////////////////////////////////////////////////////////////////////////////////
555555
// Single input
556556
template
557557
<
558558
typename D,
559-
typename TFunc,
559+
typename F,
560560
typename TValue
561561
>
562-
inline auto operator>>=(const RSignal<D,TValue>& inputNode, TFunc func)
563-
-> decltype(D::MakeSignal(func, inputNode))
562+
inline auto operator->*(const RSignal<D,TValue>& inputNode, F&& func)
563+
-> decltype(D::MakeSignal(std::forward<F>(func), inputNode))
564564
{
565-
return D::MakeSignal(func, inputNode);
565+
return D::MakeSignal(std::forward<F>(func), inputNode);
566566
}
567567

568568
// Multiple inputs
569569
template
570570
<
571571
typename D,
572-
typename TFunc,
572+
typename F,
573573
typename ... TValues
574574
>
575-
inline auto operator>>=(InputPack<D,TValues ...>& inputPack, TFunc func)
576-
-> decltype(apply(REACT_IMPL::ApplyHelper<D, TFunc, TValues ...>
577-
::MakeSignal, std::tuple_cat(std::make_tuple(func), inputPack.Data)))
575+
inline auto operator->*(const InputPack<D,TValues ...>& inputPack, F&& func)
576+
-> decltype(apply(REACT_IMPL::ApplyHelper<D, F&&, TValues ...>
577+
::MakeSignal, std::tuple_cat(std::forward_as_tuple(std::forward<F>(func)), inputPack.Data)))
578578
{
579-
return apply(REACT_IMPL::ApplyHelper<D, TFunc, TValues ...>
580-
::MakeSignal, std::tuple_cat(std::make_tuple(func), inputPack.Data));
579+
return apply(REACT_IMPL::ApplyHelper<D, F&&, TValues ...>
580+
::MakeSignal, std::tuple_cat(std::forward_as_tuple(std::forward<F>(func)), inputPack.Data));
581581
}
582582

583583
////////////////////////////////////////////////////////////////////////////////////////

src/benchmark/BenchmarkFanout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct Benchmark_Fanout : public BenchmarkBase<D>
5656

5757
for (int i=0; i<params.N; i++)
5858
{
59-
auto t = in >>= f;
59+
auto t = in ->* f;
6060
nodes.push_back(t);
6161
}
6262

src/benchmark/BenchmarkGrid.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ class GridGraphGenerator
6464

6565
if (shouldGrow)
6666
{
67-
auto s = (*l) >>= Function1;
67+
auto s = (*l) ->* Function1;
6868
nextBuf->push_back(s);
6969
}
7070

7171
while (r != curBuf->end())
7272
{
73-
auto s = (*l,*r) >>= Function2;
73+
auto s = (*l,*r) ->* Function2;
7474
nextBuf->push_back(s);
7575
nodeCount++;
7676
++l; ++r;
7777
}
7878

7979
if (shouldGrow)
8080
{
81-
auto s = (*l) >>= Function1;
81+
auto s = (*l) ->* Function1;
8282
nextBuf->push_back(s);
8383
nodeCount++;
8484
}

src/benchmark/BenchmarkLifeSim.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Time : public ReactiveObject<D>
3939
Signal<int> TotalDays = Iterate(0, NewDay, Incrementer<int>());
4040
Signal<int> DayOfYear = TotalDays % 365;
4141

42-
Signal<Seasons> Season = DayOfYear >>= [] (int day) {
42+
Signal<Seasons> Season = DayOfYear ->* [] (int day) {
4343
return day < 180 ? Seasons::winter : Seasons::summer;
4444
};
4545
};
@@ -60,12 +60,12 @@ class Region : public ReactiveObject<D>
6060
return m == Migration::enter ? count + 1 : count - 1;
6161
});
6262

63-
Signal<int> FoodPerDay = theTime.Season >>= [] (Seasons season) {
63+
Signal<int> FoodPerDay = theTime.Season ->* [] (Seasons season) {
6464
return season == Seasons::summer ? 20 : 10;
6565
};
6666

6767
Signal<int> FoodOutputPerDay =
68-
(FoodPerDay, AnimalCount) >>= [] (int food, int count) {
68+
(FoodPerDay, AnimalCount) ->* [] (int food, int count) {
6969
return count > 0 ? food/count : 0;
7070
};
7171

@@ -169,7 +169,7 @@ class Animal : public ReactiveObject<D>
169169
return CurrentRegion.Value()->Clamp(position);
170170
});
171171

172-
NewRegion = (Position) >>= [this] (PositionT pos)
172+
NewRegion = (Position) ->* [this] (PositionT pos)
173173
{
174174
return theWorld.GetRegion(pos);
175175
};

src/benchmark/BenchmarkRandom.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,20 @@ class RandomGraphGenerator
133133

134134
if (edgeCount == 2)
135135
{
136-
nodes[cur] = (nodes[kNode0], nodes[rNode1]) >>= f2;
136+
nodes[cur] = (nodes[kNode0], nodes[rNode1]) ->* f2;
137137
}
138138
else if (edgeCount == 3)
139139
{
140-
nodes[cur] = (nodes[kNode0], nodes[rNode1], nodes[rNode2]) >>= f3;
140+
nodes[cur] = (nodes[kNode0], nodes[rNode1], nodes[rNode2]) ->* f3;
141141
}
142142
else
143143
{
144-
nodes[cur] = (nodes[kNode0], nodes[rNode1], nodes[rNode2], nodes[rNode3]) >>= f4;
144+
nodes[cur] = (nodes[kNode0], nodes[rNode1], nodes[rNode2], nodes[rNode3]) ->* f4;
145145
}
146146
}
147147
else
148148
{
149-
nodes[cur] = nodes[cur-Width] >>= f1;
149+
nodes[cur] = nodes[cur-Width] ->* f1;
150150
}
151151

152152
cur++;

src/benchmark/BenchmarkSequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct Benchmark_Sequence : public BenchmarkBase<D>
5656

5757
MyHandle cur = in;
5858
for (int i=0; i<params.N; i++)
59-
cur = cur >>= f;
59+
cur = cur ->* f;
6060

6161
initializing = false;
6262

src/sandbox/Main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void SignalExample2()
5151
auto height = D::MakeVar(70);
5252
auto depth = D::MakeVar(8);
5353

54-
auto volume = (width,height,depth) >>= [] (int w, int h, int d) {
54+
auto volume = (width,height,depth) ->* [] (int w, int h, int d) {
5555
return w * h * d;
5656
};
5757

@@ -142,8 +142,6 @@ class Person : public ReactiveObject<D>
142142
Signal<int> Health = 100 - Age;
143143
Signal<int> Wisdom = Age * Age / 100;
144144

145-
Signal<int> Test;
146-
147145
// Note: Initializing them directly uses the same lambda for both signals...
148146
// compiler bug?
149147
Observer wisdomObs;

src/test/SignalTest.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ TYPED_TEST_P(SignalTest, FunctionBind1)
272272
auto v2 = MyDomain::MakeVar(30);
273273
auto v3 = MyDomain::MakeVar(10);
274274

275-
auto signal = (v1, v2, v3) >>= [=] (int a, int b, int c) -> int
275+
auto signal = (v1, v2, v3) ->* [=] (int a, int b, int c) -> int
276276
{
277277
return a * b * c;
278278
};
@@ -294,9 +294,9 @@ TYPED_TEST_P(SignalTest, FunctionBind2)
294294
auto a = MyDomain::MakeVar(1);
295295
auto b = MyDomain::MakeVar(1);
296296

297-
auto c = ((a+b), (a+100)) >>= myfunc;
298-
auto d = c >>= myfunc2;
299-
auto e = (d,d) >>= myfunc3;
297+
auto c = ((a+b), (a+100)) ->* myfunc;
298+
auto d = c ->* myfunc2;
299+
auto e = (d,d) ->* myfunc3;
300300
auto f = -e + 100;
301301

302302
ASSERT_EQ(c(),103);

src/test/TransactionTest.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,22 @@ TYPED_TEST_P(TransactionTest, Concurrent3)
170170
};
171171

172172
auto n1 = MyDomain::MakeVar(1);
173-
auto n2 = n1 >>= f_0;
174-
auto n3 = ((n2, n1) >>= f_n) >>= f_0;
175-
auto n4 = n3 >>= f_0;
176-
auto n5 = ((((n4, n3) >>= f_n), n1) >>= f_n) >>= f_0;
177-
auto n6 = n5 >>= f_0;
178-
auto n7 = ((n6, n5) >>= f_n) >>= f_0;
179-
auto n8 = n7 >>= f_0;
180-
auto n9 = ((((((n8, n7) >>= f_n), n5) >>= f_n), n1) >>= f_n) >>= f_0;
181-
auto n10 = n9 >>= f_0;
182-
auto n11 = ((n10, n9) >>= f_n) >>= f_0;
183-
auto n12 = n11 >>= f_0;
184-
auto n13 = ((((n12, n11) >>= f_n), n9) >>= f_n) >>= f_0;
185-
auto n14 = n13 >>= f_0;
186-
auto n15 = ((n14, n13) >>= f_n) >>= f_0;
187-
auto n16 = n15 >>= f_0;
188-
auto n17 = ((((((n16, n15) >>= f_n), n13) >>= f_n), n9) >>= f_n) >>= f_0;
173+
auto n2 = n1 ->* f_0;
174+
auto n3 = ((n2, n1) ->* f_n) ->* f_0;
175+
auto n4 = n3 ->* f_0;
176+
auto n5 = ((((n4, n3) ->* f_n), n1) ->* f_n) ->* f_0;
177+
auto n6 = n5 ->* f_0;
178+
auto n7 = ((n6, n5) ->* f_n) ->* f_0;
179+
auto n8 = n7 ->* f_0;
180+
auto n9 = ((((((n8, n7) ->* f_n), n5) ->* f_n), n1) ->* f_n) ->* f_0;
181+
auto n10 = n9 ->* f_0;
182+
auto n11 = ((n10, n9) ->* f_n) ->* f_0;
183+
auto n12 = n11 ->* f_0;
184+
auto n13 = ((((n12, n11) ->* f_n), n9) ->* f_n) ->* f_0;
185+
auto n14 = n13 ->* f_0;
186+
auto n15 = ((n14, n13) ->* f_n) ->* f_0;
187+
auto n16 = n15 ->* f_0;
188+
auto n17 = ((((((n16, n15) ->* f_n), n13) ->* f_n), n9) ->* f_n) ->* f_0;
189189

190190
Observe(n17, [&] (int v)
191191
{
@@ -239,7 +239,7 @@ TYPED_TEST_P(TransactionTest, Merging1)
239239
};
240240

241241
auto n1 = MyDomain::MakeVar(1);
242-
auto n2 = n1 >>= f;
242+
auto n2 = n1 ->* f;
243243

244244
Observe(n2, [&] (int v)
245245
{

0 commit comments

Comments
 (0)