If you request a type different from the actual stored type, an error message like this will be displayed:
[error] toml::value::as_string(): bad_cast to string
--> input.toml
|
1 | a = 123_456
| ^^^^^^^-- the actual type is integer
Such error messages can also be produced for user-specific algorithm that is not related to TOML syntax.
cpp
const toml::value& a = input.at("a");
if(a.as_integer() ("input.toml");
Here, toml::ordered_value is an alias of toml::basic_value.
Note that, since toml::value uses std::unordered_map, once you convert it to toml::value, then the order of the values will be randomized.
For more details about how to implement type_config variant, please refer to the documentation.
Also, refer to the examples directory for complex use cases such as using multi-precision integers, changing containers, and normalizing Unicode.
Use these examples as references for implementing such configurations.
Examples
The examples directory provides various implementation examples in addition to type configurations.
This example demonstrates normalizing Unicode strings when searching for keys using uni-algo.
Changes from v3
toml11 v4 introduces several breaking changes.
Efforts have been made to minimize the need for changes for those using simple functionality.
However, if you were utilizing advanced features, some adjustments may be necessary.
Nevertheless, we believe that the added or streamlined features will provide enhanced convenience in return.
Breaking Changes
Changed branch from master to main.
Changed template arguments of toml::basic_value.
Removed toml::string and explicitly store formatting information of all the values.
Modified arguments of toml::format to accommodate formatting information.
Changed default arguments of toml::parse to take toml::spec for specifying TOML version information.
Updated the interface of toml::source_location to accommodate multiline regions.
Modified arguments of toml::format_error.
Renamed toml::format_underline to toml::format_location.
Unified control method of toml::color to toml::color::enable/disable().
Added features
Added toml::parse_str.
Added toml::try_parse.
Added support for parsing byte sequences.
Added formatting information to toml::value.
Changed to saving comments in toml::value by default.
Added single_include/toml.hpp.
Enabled to use as a precompiled library.
Contributors
I appreciate the help of the contributors who introduced the great feature to this library.
Guillaume Fraux (@Luthaf)
Windows support and CI on Appvayor
Intel Compiler support
Quentin Khan (@xaxousis)
Found & Fixed a bug around ODR
Improved error messages for invalid keys to show the location where the parser fails
Petr Beneš (@wbenny)
Fixed warnings on MSVC
Ivan Shynkarenka (@chronoxor)
Fixed Visual Studio 2019 warnings
Fix compilation error in `` with MinGW
Khoi Dinh Trinh (@khoitd1997)
Fixed warnings while type conversion
@KerstinKeller
Added installation script to CMake
J.C. Moyer (@jcmoyer)
Fixed an example code in the documentation
Jt Freeman (@blockparty-sh)
Fixed feature test macro around localtime_s
Suppress warnings in Debug mode
OGAWA Kenichi (@kenichiice)
Suppress warnings on intel compiler
Fix include path in README
Jordan Williams (@jwillikers)
Fixed clang range-loop-analysis warnings
Fixed feature test macro to suppress -Wundef
Use cache variables in CMakeLists.txt
Automate test set fetching, update and refactor CMakeLists.txt
Scott McCaskill
Parse 9 digits (nanoseconds) of fractional seconds in a local_time
Shu Wang (@halfelf)
fix "Finding a value in an array" example in README
@maass-tv and @SeverinLeonhardt
Fix MSVC warning C4866
Mohammed Alyousef (@MoAlyousef)
Made testing optional in CMake
Alex Merry (@amerry)
Add missing include files
sneakypete81 (@sneakypete81)
Fix typo in error message
Oliver Kahrmann (@founderio)
Fix missing filename in error message if parsed file is empty
Karl Nilsson (@karl-nilsson)
Fix many spelling errors
ohdarling88 (@ohdarling)
Fix a bug in a constructor of serializer
estshorter (@estshorter)
Fix MSVC warning C26478
Philip Top (@phlptp)
Improve checking standard library feature availability check
Louis Marascio (@marascio)
Fix free-nonheap-object warning
Axel Huebl (@ax3l)
Make installation optional if the library is embedded
Ken Matsui (@ken-matsui)
Support user-defined error message prefix
Support dynamic color mode
Support std::optional members for TOML11_DEFINE_CONVERSION_NON_INTRUSIVE
Make thread_local for color_mode optional
Add toml::find_or_default
Fix static assertions in success that checks if specified type is void
Giel van Schijndel (@muggenhor)
Remove needless copy in parse function
Lukáš Hrázký (@lukash)
Add a parse(FILE *) interface and improve file-related error messages
spiderman idog (@spiderman-idog)
Fix typo in README
Jajauma's GitHub (@Jajauma)
Avoid possible lexer truncation warnings
Moritz Klammler (@ctcmkl)
Many patches in (#200) including:
Improve CMake scripts, build process, and test file handling
Detect error when discard_comments is accessed
And more.
Chris White (@cxw42)
Fix address-sanitizer error when parsing literal strings having invalid UTF-8 characters
Fix function name in error messages
offa (@offa)
Update checkout action to v3
Update Required CMake version
Cleanup old CI settings
Sergey Vidyuk (@VestniK)
Fix for case when vector iterator is raw pointer
Kfir Gollan (@kfirgollan)
Add installation example with checkinstall and cmake
Martin Tournoij (@arp242)
Escape control characters in keys
@DavidKorczynski
Add fuzzing test based on ClusterFuzzLite
Esonhugh Skyworship (@Esonhugh)
Fix function signature of strerror_r on macos
Alberto (@0X1A)
Fix issues with CMake package configuration when used with vcpkg
Egor Pugin (@egorpugin)
Fix incorrect operator<<() argument type that gives build error
Andreas Keller (@andreaskeller96)
Fix not checking for \r\n when parsing line comments
萧迩珀 (@CDK6182CHR)
Support template into_toml members
Pino Toscano (@pinotree)
Suppress warnings by manually cast file size to std::streamsize
Jack W (@jackwil1)
Fix typos in documentation template syntax
amatej (@kontura)
Fix: toml::detail::region::last_ may be used uninitialized
Severin Leonhardt (@SeverinLeonhardt)
Fix use with CMake 3.21 and older
hayt (@hayt)
fix: prevent size_t-max length string allocation
somebody (@oldoldtea), (lz)
Update README for better ToC, fixing example code
Sunlight (@SunPodder)
Add erase(...) function to ordered_map
Licensing terms
This product is licensed under the terms of the MIT License.