Simplify templates

This commit is contained in:
2026-07-29 23:11:48 +02:00
parent 4f6ad45b0e
commit a06c41f2c7
4 changed files with 21 additions and 42 deletions
+11 -5
View File
@@ -242,14 +242,19 @@ provide the following functions to aide in the serialization process:
}
```
- `native_type_template("type<{{T}}>")` (on a struct) together with
- `native_type_template("type")` (on a struct) together with
`native_type_template_arg("type")` (on a field of that struct type):
lets a single struct declaration back a native type that is a C++
template, instantiated differently per field, instead of requiring one
struct declaration (and `native_type`) per instantiation. For example:
struct declaration (and `native_type`) per instantiation.
`native_type_template_arg` is angle-bracket-appended to
`native_type_template` to form the field's native type, so
`native_type_template: "Native::Box"` with
`native_type_template_arg: "Native::TypeA"` produces
`Native::Box<Native::TypeA>`. For example:
```cpp
struct Box (native_type_template: "Native::Box<{{T}}>") {
struct Box (native_type_template: "Native::Box") {
value: int32;
}
@@ -271,10 +276,10 @@ is equivalent to writing, on each field itself:
functions stay unique across instantiations without spelling it out
yourself; an explicit `native_type_pack_name` on the field still overrides
this. More than one template parameter is supported by separating them with
commas and using indexed placeholders:
commas:
```cpp
struct Pair (native_type_template: "Native::Pair<{{T0}}, {{T1}}>") {
struct Pair (native_type_template: "Native::Pair") {
value: int32;
}
@@ -283,6 +288,7 @@ commas and using indexed placeholders:
}
```
which produces `Native::Pair<Native::Key, Native::Value>`.
`native_type_template_arg` is only valid on fields whose type is a struct
(or vector of structs) that declares `native_type_template`.