-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiteration.cpp
More file actions
30 lines (23 loc) · 827 Bytes
/
Copy pathiteration.cpp
File metadata and controls
30 lines (23 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import std;
import serial_xml;
// [[= serial_xml::iter{"single", "multiple"}]] lets you customise
// the tag names when iterating over ranges.
struct IterSTL {
[[= serial_xml::iter{"c_val", "container"}]] std::vector<int> values;
};
struct SingleCharIter {
[[= serial_xml::iter{"v", "vals"}]] std::vector<int> values;
};
// You can iterate over a range of structs too.
struct InnerItem {
int x;
};
struct StructInRangeOuter {
[[= serial_xml::iter{"inner", "inners"}]] std::vector<InnerItem> inners;
};
int main() {
std::print("Custom iter names:\n {}\n", serial_xml::to_xml(IterSTL{{1, 2, 3}}));
std::print("Single-char iter names:\n {}\n", serial_xml::to_xml(SingleCharIter{{1, 2, 3}}));
std::print("Structs in a range:\n {}\n",
serial_xml::to_xml(StructInRangeOuter{{{1}, {2}, {3}}}));
}