1 /* A class that sets a boolean when an object of the class gets destroyed.
4 S(bool *freed
) : freed(freed
) {}
12 * Set the boolean, a pointer to which was passed to the constructor.
19 /* Construct an isl::id with an S object attached that sets *freed
20 * when it gets destroyed.
22 static isl::id
construct_id(isl::ctx ctx
, bool *freed
)
24 auto s
= std::make_shared
<S
>(freed
);
25 isl::id
id(ctx
, "S", s
);
31 * In particular, check that the object attached to an identifier
32 * can be retrieved again, that trying to retrieve an object of the wrong type
33 * or trying to retrieve an object when no object was attached fails.
34 * Furthermore, check that the object attached to an identifier
35 * gets properly freed.
37 static void test_try_user(isl::ctx ctx
)
39 isl::id
id(ctx
, "test", 5);
40 isl::id
id2(ctx
, "test2");
42 auto maybe_int
= id
.try_user
<int>();
43 auto maybe_s
= id
.try_user
<std::shared_ptr
<S
>>();
44 auto maybe_int2
= id2
.try_user
<int>();
47 die("integer cannot be retrieved from isl::id");
48 if (maybe_int
.value() != 5)
49 die("wrong integer retrieved from isl::id");
51 die("structure unexpectedly retrieved from isl::id");
53 die("integer unexpectedly retrieved from isl::id");
57 isl::id id
= construct_id(ctx
, &freed
);
59 die("data structure freed prematurely");
60 auto maybe_s
= id
.try_user
<std::shared_ptr
<S
>>();
62 die("structure cannot be retrieved from isl::id");
63 if (maybe_s
.value()->freed
!= &freed
)
64 die("invalid structure retrieved from isl::id");
67 die("data structure not freed");