mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00
feat: add examples
This commit is contained in:
38
examples/reflect/reflect.cpp
Normal file
38
examples/reflect/reflect.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <reflect>
|
||||
#include "reflect.hpp"
|
||||
|
||||
struct Hoge
|
||||
{
|
||||
int foo;
|
||||
double bar;
|
||||
std::string baz;
|
||||
};
|
||||
TOML11_REFLECT(Hoge)
|
||||
|
||||
int main()
|
||||
{
|
||||
toml::value v(toml::table{
|
||||
{"foo", 42},
|
||||
{"bar", 3.14},
|
||||
{"baz", "fuga"},
|
||||
});
|
||||
|
||||
const Hoge h = toml::get<Hoge>(v);
|
||||
|
||||
std::cout << "Hoge.foo = " << h.foo << std::endl;
|
||||
std::cout << "Hoge.bar = " << h.bar << std::endl;
|
||||
std::cout << "Hoge.baz = " << h.baz << std::endl;
|
||||
|
||||
Hoge h2;
|
||||
h2.foo = 6 * 9;
|
||||
h2.bar = 2.718;
|
||||
h2.baz = "piyo";
|
||||
|
||||
toml::value v2(h2);
|
||||
|
||||
std::cout << toml::format(v2);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user