diff options
-rw-r--r-- | cells-test.cpp | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/cells-test.cpp b/cells-test.cpp index a88fe5b..539ee56 100644 --- a/cells-test.cpp +++ b/cells-test.cpp @@ -31,25 +31,32 @@ typedef formula_cell<unit> ucell; int main(int argc, char** argv) { - fcell x0, x1, x2, y, z; - ucell a, b; + fcell x0, x1, x2, y; + ucell b; - with_transaction([&](){ - x0.reset(10); - x1.reset([&](){ return *x0 + 5; }); - x2.reset([&](){ return *x0 * 2; }); - y.reset([&](){ return *x1 * *x2; }); - z.reset([&](){ return *x0 * *y; }); - a.reset([&]() -> unit { cout << "z is now " << *z << "." << endl; return unit(); }); - b.reset([&]() -> unit { cout << "x2 is now " << *x2 << "." << endl; return unit(); }); - }); - - x0.reset(15); - x0.reset(-20); - y.reset(-3); - x1.reset([&]() { return (double)*x0; }); - y.reset([&]() { return *x1 + *x2; }); + { + fcell z; + ucell a; + with_transaction([&](){ + x0.reset(10); + x1.reset([&](){ return *x0 + 5; }); + x2.reset([&](){ return *x0 * 2; }); + y.reset([&](){ return *x1 * *x2; }); + z.reset([&](){ return *x0 * *y; }); + a.reset([&]() -> unit { cout << "z is now " << *z << "." << endl; return unit(); }); + b.reset([&]() -> unit { cout << "x2 is now " << *x2 << "." << endl; return unit(); }); + }); + + x0.reset(15); + x0.reset(-20); + y.reset(-3); + x1.reset([&]() { return (double)*x0; }); + y.reset([&]() { return *x1 + *x2; }); + } + x0.reset(10); //z and a are not active anymore, so only b will + //produce output. + return EXIT_SUCCESS; } |