From f9ab7d6f56802842f67a317fde1e0e7b4469abef Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 14 Apr 2019 20:08:23 +0900 Subject: [PATCH] chore: add note about literals to README.md --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index ed28ec2..495a07a 100644 --- a/README.md +++ b/README.md @@ -603,6 +603,25 @@ toml::value operator""_toml(const char* str, std::size_t len); Access to the operator can be gained with `using namespace toml::literals;`, `using namespace toml::toml_literals`, and `using namespace toml::literals::toml_literals`. +Note that since it allows a bare value without a key, it is difficult to distinguish +arrays and table definitions. +Currently, it parses `[1]` as a table definition if there are no commas. +To ensure a literal to be considered as an array with one element, you need to +add a comma after the first element (like `[1,]`). + +```cpp +"[1,2,3]"_toml; // This is an array +"[table]"_toml; // This is a table that has an empty table named "table" inside. +"[[1,2,3]]"_toml; // This is an array of arrays +"[[table]]"_toml; // This is a table that has an array of tables inside. + +"[[1]]"_toml; // This is ambiguous. + // Currently, it becomes a table taht has array of table "1". +"1 = [{}]"_toml; // This is a table that has an array of table named 1. +"[[1,]]"_toml; // This is an array of arrays. +"[[1],]"_toml; // ditto. +``` + ## Conversion between toml value and arbitrary types You can also use `toml::get` and other related functions with the types you defined