Skip to content

Commit bd42f8d

Browse files
committed
Update union_test note to mention unique addresses and common initial sequences
1 parent 9875306 commit bd42f8d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

experimental/union_test.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,29 @@
2020
// Tag discriminator tag to store for each object (uintNN_t where
2121
// NN is large enough to hold the #alternatives in the union)
2222
//
23-
// For an object U of union type, when inject a call to this (zero-based alternative #s)
24-
// U is created initialized on_set_alternative(&U,0) = the first alternative# is active
25-
// U is created uninitialized on_set_alternative(&U,invalid)
26-
// U.A = xxx (alt #A is assigned to) on_set_alternative(&U,A)
27-
// U.A (alt #A is otherwise mentioned) on_get_alternative(&U,A)
28-
// U is destroyed / goes out of scope on_destroy(&U)
23+
// For an object U of union type that
24+
// has a unique address, when inject a call to this (zero-based alternative #s)
25+
//
26+
// U is created initialized on_set_alternative(&U,0) = the first alternative# is active
27+
//
28+
// U is created uninitialized on_set_alternative(&U,invalid)
29+
//
30+
// U.A = xxx (alt #A is assigned to) on_set_alternative(&U,#A)
31+
//
32+
// U.A (alt #A is otherwise mentioned) on_get_alternative(&U,#A)
33+
// and A is not a common initial
34+
// sequence
35+
//
36+
// U is destroyed / goes out of scope on_destroy(&U)
2937
//
3038
// That's it. Here's an example:
3139
// {
3240
// union Test { int a; double b; };
33-
// Test t = {42}; union_registry<>::on_set_alternative(&u,0);
34-
// std::cout << t.a; union_registry<>::on_get_alternative(&u,0);
35-
// t.b = 3.14159; union_registry<>::on_set_alternative(&u,1);
36-
// std::cout << t.b; union_registry<>::on_get_alternative(&u,1);
37-
// } union_registry<>::on_destroy(&u);
41+
// Test t = {42}; union_registry<>::on_set_alternative(&u,0);
42+
// std::cout << t.a; union_registry<>::on_get_alternative(&u,0);
43+
// t.b = 3.14159; union_registry<>::on_set_alternative(&u,1);
44+
// std::cout << t.b; union_registry<>::on_get_alternative(&u,1);
45+
// } union_registry<>::on_destroy(&u);
3846
//
3947
// For all unions with under 256 alternatives, use union_registry<>
4048
// For all unions with between 256 and 16k alternatives, use union_registry<uint16_t>

0 commit comments

Comments
 (0)