1 Star 8 Fork 2

Gitee 极速下载/reflect-cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/getml/reflect-cpp
克隆/下载
standard_containers.md 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
liuzicheng1987 提交于 2年前 . Fixed typo

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:

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

This will be represented as follows:

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

The same is true for numeric types:

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

This will be represented as follows:

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

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

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:

{"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.

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/reflect-cpp.git
git@gitee.com:mirrors/reflect-cpp.git
mirrors
reflect-cpp
reflect-cpp
f/bit_cast

搜索帮助