wibble
1.1
Main Page
Namespaces
Classes
Files
File List
File Members
wibble
raii.test.h
Go to the documentation of this file.
1
#if __cplusplus >= 201103L
2
#include <
wibble/raii.h
>
3
using namespace
wibble::raii;
4
#endif
5
6
#include <
wibble/test.h
>
7
8
9
struct
TestRAII
{
10
#if __cplusplus >= 201103L
11
Test
basic() {
12
int
y = 0;
13
{
14
auto
del = autoDeleter( []() ->
int
{
return
5; }, [ &y ](
int
x ) {
15
assert_eq
( x, 10 );
16
y = x;
17
} );
18
assert_eq
( y, 0 );
19
assert_eq
( del.value, 5 );
20
del.value = 10;
21
}
22
assert_eq
( y, 10 );
23
}
24
25
Test
ref() {
26
int
x = 5;
27
{
28
auto
del = refDeleter( x, [](
int
&y ) {
29
y = 10;
30
} );
31
assert_eq
( del.value, 5 );
32
assert_eq
( x, 5 );
33
}
34
assert_eq
( x, 10 );
35
}
36
37
Test
refIf() {
38
int
x = 5;
39
{
40
auto
del = refDeleteIf(
true
, x, [](
int
&y ) { y = 10; } );
41
assert_eq
( x, 5 );
42
}
43
assert_eq
( x, 10 );
44
{
45
auto
del = refDeleteIf(
false
, x, [](
int
&y ) { y = 15; } );
46
assert_eq
( x, 10 );
47
}
48
assert_eq
( x, 10 );
49
}
50
51
static
void
delFn(
int
&x ) { x = 0; }
52
53
Test
fn() {
54
int
x = 5;
55
{
56
AutoDelete< int & > del( x, delFn );
57
assert_eq
( x, 5 );
58
}
59
assert_eq
( x, 0 );
60
}
61
#else
/* FIXME: workaround */
62
void
basic
() {}
63
void
ref
() {}
64
void
refIf
() {}
65
void
fn
() {}
66
#endif
67
};
Generated on Wed Oct 23 2013 17:14:25 for wibble by
1.8.4