-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstl_containers.cpp
More file actions
34 lines (26 loc) · 1001 Bytes
/
Copy pathstl_containers.cpp
File metadata and controls
34 lines (26 loc) · 1001 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
31
32
33
34
import std;
import serial_xml;
// STL containers like std::vector are iterated automatically,
// producing <element> tags for each item.
struct VectorExample {
std::vector<int> values;
};
struct EmptyVector {
std::vector<int> values;
};
// [[= serial_xml::exclude_on_empty]] omits the entire member
// when the container is empty.
struct ExcludeOnEmpty {
[[= serial_xml::exclude_on_empty]] std::vector<int> values;
};
// [[= serial_xml::no_iter]] treats the container as a single
// value, calling std::format instead of iterating.
struct NoIter {
[[= serial_xml::no_iter]] std::vector<int> values;
};
int main() {
std::print("Vector (auto-iterated):\n {}\n", serial_xml::to_xml(VectorExample{{1, 2, 3}}));
std::print("Empty vector:\n {}\n", serial_xml::to_xml(EmptyVector{{}}));
std::print("Exclude on empty (empty vector):\n {}\n", serial_xml::to_xml(ExcludeOnEmpty{{}}));
std::print("No-iterate (formatted as a whole):\n {}\n", serial_xml::to_xml(NoIter{{1, 2, 3}}));
}