Skip to content

Commit dd55353

Browse files
committed
Eliminate EventQueue contexts
Can just use lambda capture.
1 parent 013377a commit dd55353

File tree

1 file changed

+3
-106
lines changed

1 file changed

+3
-106
lines changed

events/EventQueue.h

+3-106
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
643643
template <typename F, typename... ArgTs>
644644
int call(F f, ArgTs... args)
645645
{
646-
return call(context<F, ArgTs...>(f, args...));
646+
return call([=] { f(args...); }); // *NOPAD*
647647
}
648648

649649
/** Calls an event on the queue
@@ -719,7 +719,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
719719
template <typename F, typename... ArgTs>
720720
int call_in(int ms, F f, ArgTs... args)
721721
{
722-
return call_in(ms, context<F, ArgTs...>(f, args...));
722+
return call_in(ms, [=] { f(args...); }); // *NOPAD*
723723
}
724724

725725
/** Calls an event on the queue after a specified delay
@@ -799,7 +799,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
799799
template <typename F, typename... ArgTs>
800800
int call_every(int ms, F f, ArgTs... args)
801801
{
802-
return call_every(ms, context<F, ArgTs...>(f, args...));
802+
return call_every(ms, [=] { f(args...); }); // *NOPAD*
803803
}
804804

805805
/** Calls an event on the queue periodically
@@ -1080,109 +1080,6 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
10801080
{
10811081
((F *)p)->~F();
10821082
}
1083-
1084-
// Context structures
1085-
template <typename F, typename... ContextArgTs>
1086-
struct context;
1087-
1088-
template <typename F>
1089-
struct context<F> {
1090-
F f;
1091-
1092-
context(F f)
1093-
: f(f) {}
1094-
1095-
template <typename... ArgTs>
1096-
void operator()(ArgTs... args)
1097-
{
1098-
f(args...);
1099-
}
1100-
};
1101-
1102-
template <typename F, typename C0>
1103-
struct context<F, C0> {
1104-
F f;
1105-
C0 c0;
1106-
1107-
context(F f, C0 c0)
1108-
: f(f), c0(c0) {}
1109-
1110-
template <typename... ArgTs>
1111-
void operator()(ArgTs... args)
1112-
{
1113-
f(c0, args...);
1114-
}
1115-
};
1116-
1117-
template <typename F, typename C0, typename C1>
1118-
struct context<F, C0, C1> {
1119-
F f;
1120-
C0 c0;
1121-
C1 c1;
1122-
1123-
context(F f, C0 c0, C1 c1)
1124-
: f(f), c0(c0), c1(c1) {}
1125-
1126-
template <typename... ArgTs>
1127-
void operator()(ArgTs... args)
1128-
{
1129-
f(c0, c1, args...);
1130-
}
1131-
};
1132-
1133-
template <typename F, typename C0, typename C1, typename C2>
1134-
struct context<F, C0, C1, C2> {
1135-
F f;
1136-
C0 c0;
1137-
C1 c1;
1138-
C2 c2;
1139-
1140-
context(F f, C0 c0, C1 c1, C2 c2)
1141-
: f(f), c0(c0), c1(c1), c2(c2) {}
1142-
1143-
template <typename... ArgTs>
1144-
void operator()(ArgTs... args)
1145-
{
1146-
f(c0, c1, c2, args...);
1147-
}
1148-
};
1149-
1150-
template <typename F, typename C0, typename C1, typename C2, typename C3>
1151-
struct context<F, C0, C1, C2, C3> {
1152-
F f;
1153-
C0 c0;
1154-
C1 c1;
1155-
C2 c2;
1156-
C3 c3;
1157-
1158-
context(F f, C0 c0, C1 c1, C2 c2, C3 c3)
1159-
: f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}
1160-
1161-
template <typename... ArgTs>
1162-
void operator()(ArgTs... args)
1163-
{
1164-
f(c0, c1, c2, c3, args...);
1165-
}
1166-
};
1167-
1168-
template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
1169-
struct context<F, C0, C1, C2, C3, C4> {
1170-
F f;
1171-
C0 c0;
1172-
C1 c1;
1173-
C2 c2;
1174-
C3 c3;
1175-
C4 c4;
1176-
1177-
context(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
1178-
: f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}
1179-
1180-
template <typename... ArgTs>
1181-
void operator()(ArgTs... args)
1182-
{
1183-
f(c0, c1, c2, c3, c4, args...);
1184-
}
1185-
};
11861083
#endif //!defined(DOXYGEN_ONLY)
11871084
};
11881085

0 commit comments

Comments
 (0)