1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <asyncfuture.h>
using namespace AsyncFuture;
//@FIXME - validate context function
/** static_assert() should be able to capture all kind of compiler errors in following conditions,
* instead of reporting confusing compiler errors
*/
#define ENABLED
// Case 1 - More than 1 argument in callback function
#if defined(ENABLED)
static void case1a() { // subscribe - no return
auto defer = Deferred<int>();
observe(defer.future()).subscribe([=](int a, int b) {
Q_UNUSED(a);
Q_UNUSED(b);
});
}
#endif
#if defined(ENABLED)
static void case1b() { // subscribe - with return
auto defer = Deferred<int>();
observe(defer.future()).subscribe([=](int a, int b) {
Q_UNUSED(a);
Q_UNUSED(b);
return 99;
});
}
#endif
#if defined(ENABLED)
static void case1c() { // context - with return
auto defer = Deferred<int>();
QObject tmp;
observe(defer.future()).context(&tmp, [=](int a, int b) {
Q_UNUSED(a);
Q_UNUSED(b);
return 99;
});
}
#endif
// Case 2 - observe a QFuture<void> by a callback with input argument
#if defined(ENABLED)
static void case2a() {
auto defer = Deferred<void>();
observe(defer.future()).subscribe([=](int a) {
Q_UNUSED(a);
});
}
#endif
#if defined(ENABLED)
static void case2b() {
auto defer = Deferred<void>();
QObject tmp;
observe(defer.future()).context(&tmp, [=](int a) {
Q_UNUSED(a);
});
}
#endif
// Case 3 - the type is mismatched.
#if defined(ENABLED)
static void case3() {
//@FIXME - the static_assert error message is missing
auto defer = Deferred<QString>();
observe(defer.future()).subscribe([=](int a) {
Q_UNUSED(a);
});
}
#endif
|