-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_specifiers.cpp
More file actions
29 lines (23 loc) · 861 Bytes
/
Copy pathformat_specifiers.cpp
File metadata and controls
29 lines (23 loc) · 861 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
import std;
import serial_xml;
// [[= serial_xml::format{"..."}]] passes a format specifier
// to std::format for that member's value.
struct FormattedAttribute {
[[ = serial_xml::attribute, = serial_xml::format{"03d"} ]] int x;
};
struct FormattedChild {
[[= serial_xml::format{"03d"}]] int x;
};
struct FormattedRaw {
[[ = serial_xml::raw, = serial_xml::format{"03d"} ]] int x;
};
struct FormattedStringChild {
[[= serial_xml::format{"*^12"}]] std::string text;
};
int main() {
std::print("Formatted attribute:\n {}\n", serial_xml::to_xml(FormattedAttribute{42}));
std::print("Formatted child:\n {}\n", serial_xml::to_xml(FormattedChild{42}));
std::print("Formatted raw:\n {}\n", serial_xml::to_xml(FormattedRaw{42}));
std::print("Formatted string (padded):\n {}\n",
serial_xml::to_xml(FormattedStringChild{"text"}));
}