File: standard_containers.md

package info (click to toggle)
reflect-cpp 0.18.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,524 kB
  • sloc: cpp: 44,484; python: 131; makefile: 30; sh: 3
file content (56 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Support for standard containers

The serialization and deserialization of containers is handled as follows:

`std::map<std::string, ...>`, `std::unordered_map<std::string, ...>`, 
maps with any numeric types (integral and floating points) as keys,
and any objects where the `ReflectionType` is either a `std::string` or
a numeric type are treated as objects.

Consider the following map:

```cpp
std::map<std::string, std::string> homer;
homer["firstName"] = "Homer";
homer["lastName"] = "Simpson";
```

This will be represented as follows:

```json
{"firstName":"Homer","lastName":"Simpson"}
```

The same is true for numeric types:

```cpp
std::map<int, std::string> homer;
homer[1] = "Homer";
homer[2] = "Simpson";
```

This will be represented as follows:

```json
{"1":"Homer","2":"Simpson"}
```

If you wrap your keys into a `rfl::Validator`, this will be treated as an object as well:

```cpp
using Between1and3 = rfl::Validator<int, rfl::Minimum<1>, rfl::Maximum<3>>;
std::map<Between1and3, std::string> homer;
homer[1] = "Homer";
homer[2] = "Simpson";
```

This will also be represented as follows:

```json
{"1":"Homer","2":"Simpson"}
```

All other supported standard containers 
(other than `std::variant`, `std::optional`, `std::unique_ptr` and `std::shared_ptr`) 
will be represented as arrays. Containers for which the `value_type`
is a key-value-pair will be represented as arrays of pairs.