diff --git a/README.md b/README.md index 3be2497..d1acaf1 100644 --- a/README.md +++ b/README.md @@ -895,12 +895,10 @@ add a comma after the first element (like `[1,]`). NOTE: `_toml` literal returns a `toml::value` that does not have comments. - - ## Conversion between toml value and arbitrary types -You can also use `toml::get` and other related functions with the types you defined -after you implement some stuff. +You can also use `toml::get` and other related functions with the types +you defined after you implement a way to convert it. ```cpp namespace ext @@ -915,7 +913,8 @@ struct foo const auto data = toml::parse("example.toml"); -const foo f = toml::get(data.at("foo")); +// to do this +const foo f = toml::find(data, "foo"); ``` There are 2 ways to use `toml::get` with the types that you defined. @@ -963,12 +962,12 @@ namespace toml template<> struct from { - ext::foo from_toml(const toml::value& v) + ext::foo from_toml(const value& v) { ext::foo f; - f.a = toml::find(v, "a"); - f.b = toml::find(v, "b"); - f.c = toml::find(v, "c"); + f.a = find(v, "a"); + f.b = find(v, "b"); + f.c = find(v, "c"); return f; } }; @@ -981,6 +980,40 @@ you can add conversion between `toml::value` and classes defined in another libr Note that you cannot implement both of the functions because the overload resolution of `toml::get` will be ambiguous. +If you want to convert arbitrary specialization of `toml::basic_value`, +templatize the conversion function as follows. + +```cpp +struct foo +{ + template class M, template class A> + void from_toml(const toml::basic_value& v) + { + this->a = toml::find(v, "a"); + this->b = toml::find(v, "b"); + this->c = toml::find(v, "c"); + return; + } +}; +// or +namespace toml +{ +template<> +struct from +{ + template class M, template class A> + ext::foo from_toml(const basic_value& v) + { + ext::foo f; + f.a = find(v, "a"); + f.b = find(v, "b"); + f.c = find(v, "c"); + return f; + } +}; +} // toml +``` + ---- The opposite direction is also supported in a similar way. You can directly