Skip to content

Commit 27351e0

Browse files
committed
[sample]
1 parent 307ef18 commit 27351e0

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Tagged Pointer
2+
3+
a lightweight tagged pointer library for C++20
4+
5+
provide a tuple-like tagged pointer
6+
7+
8+
```c++
9+
"sample1"_test = [] {
10+
int a = 0;
11+
tp::tagged_ptr<int, bool, bool> p = &a;
12+
13+
//bool,bool
14+
const auto [b1,b2] = p;
15+
16+
//bool ref, bool ref
17+
auto& [b1_ref,b2_ref] = p;
18+
b1_ref = true;
19+
b2_ref = true;
20+
};
21+
22+
"sample2"_test = [] {
23+
24+
enum class Flag {
25+
None = 0,
26+
A = 1 << 0,
27+
B = 1 << 1
28+
};
29+
30+
int a = 0;
31+
tp::tagged_ptr<int, tp::tag_of<Flag,2>> p = &a;
32+
33+
auto& [b1] = p;
34+
b1 = Flag::A;
35+
36+
};
37+
38+
"sample3"_test = [] {
39+
40+
int a = 0;
41+
//low bits: 2 + x86_64 high bits reserve: 16
42+
tp::tagged_ptr<int, bool, bool, uint16_t> p = &a;
43+
44+
const auto [b1,b2,i] = p;
45+
46+
};
47+
```
48+

test/sample.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "../src/tagged_ptr.h"
2+
#include "ut.hpp"
3+
4+
using namespace boost::ut;
5+
6+
suite sample = [] {
7+
8+
"sample1"_test = [] {
9+
int a = 0;
10+
tp::tagged_ptr<int, bool, bool> p = &a;
11+
12+
//bool,bool
13+
const auto [b1,b2] = p;
14+
15+
//bool ref, bool ref
16+
auto& [b1_ref,b2_ref] = p;
17+
b1_ref = true;
18+
b2_ref = true;
19+
};
20+
21+
"sample2"_test = [] {
22+
23+
enum class Flag {
24+
None = 0,
25+
A = 1 << 0,
26+
B = 1 << 1
27+
};
28+
29+
int a = 0;
30+
tp::tagged_ptr<int, tp::tag_of<Flag,2>> p = &a;
31+
32+
auto& [b1] = p;
33+
b1 = Flag::A;
34+
35+
};
36+
37+
"sample3"_test = [] {
38+
39+
int a = 0;
40+
//low bits: 2 + x86_64 high bits reserve: 16
41+
tp::tagged_ptr<int, bool, bool, uint16_t> p = &a;
42+
43+
const auto [b1,b2,i] = p;
44+
45+
};
46+
47+
"sample4"_test = [] {
48+
49+
tp::tagged_ptr<void, uint16_t> p;
50+
51+
const auto [i] = p;
52+
53+
};
54+
55+
56+
};

0 commit comments

Comments
 (0)