|
Boost : |
From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2000-11-14 13:13:01
Hi,
I finally got around to testing LL with this and it works fine.
So this example could be written as:
> #include <cassert>
> #include <iostream>
#include "ll.hpp"
> using namespace std;
using boost::var;
> int main()
> {
> {
> int value = 0;
> {
> ScopeGuard restorer = boost::makeGuard(var(value) = 10);
> assert(value==0);
> value = 19;
> assert(value==19);
> }
> assert(value == 10);
> }
>
> {
> int value = 27;
> {
> ScopedGuard restorer = boost::makeGuard(var(value) = value);
>
> assert(value==27);
> value = 19;
> assert(value==19);
> }
> assert(value == 27);
> }
>
>
> return 0;
> }
>
The second case looks a bit weird, but because the "value" is not wrapped
with a var() call, its evaluated immediately, and therefore is the same as
ScopedGuard restorer = boost::makeGuard(var(value) = 27);
What's really cool about all this, is than ANY lambda expression can be put
inside this guard. And trust me, the expressions can be really complex.
(Also using LL, makes all these special cases of auto_restore, makeGuard for
various numbers of function arguments, member functions go away.)
Yours,
-gary-
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk