Possible changes for v4
Each change on this page would improve toml++, and most would also break something that users rely on today. They wait for the next major version, and none of them is decided. The appendix at the end lists related requests that aren't planned for v4.
Library
Static path::subpath() overload
toml::path::subpath(const_iterator, const_iterator) doesn't use the path it's called on, so it could be a static member function (#310). Calls through an object would still compile.
The exported symbol would change from a const member function to a static one, so programs linked against a shared build of toml++ would need rebuilding.
Paths and empty keys
A toml::path is meant to be relative to the node it's applied to, but TOML allows empty keys, and that makes some paths ambiguous. toml::path("") is one empty key. A default-constructed path is empty, and so is one built from a string that fails to parse. An empty path selects the node it's applied to, unless that node is a value or an empty container. str() loses the . between an empty key and an index, so a..[1] prints as a.[1], which is a different path.
Some other quirks: a . directly before an index is ignored, so a.[1] is the same path as a[1]. The string overloads of at_path() select nothing for a string that fails to parse, and the path overloads select the node itself for the empty path that string gives. Assigning such a string to a path empties it, and appending one leaves the path unchanged.
The path tests pin all of this as v3.4.0 had it, and v3 keeps it that way.
How paths work, and how they should work, needs a review from the ground up. Any change here would change what existing paths select or how they print.
Reverse iteration over tables
A toml::table iterator returns its key-value pair as a proxy object stored inside the iterator. std::reverse_iterator dereferences a temporary copy of the iterator, so the reference it returns outlives the proxy, and std::views::reverse does the same. Returning the proxy by value would fix it.
The iterators' reference type would change, so loops like for (auto& [k, v] : tbl) would stop compiling.
parse_result conversions without exceptions
With exceptions disabled, toml::parse_result converts implicitly to table&, table&& and const table&, and none of the conversions is ref-qualified. So toml::table t = result; is ambiguous, and toml::table& t = toml::parse(doc); compiles and dangles. Ref-qualifying the conversions fixes both, though direct-initialisation from an rvalue stays ambiguous.
Code that takes a table&& from an lvalue parse_result, or a table& from a temporary one, would stop compiling.
Mixing exception settings
Code built with and without exceptions can share a program, because most of what differs between the two is in inline namespaces named after TOML_EXCEPTIONS. These differences aren't:
toml_formatter,json_formatterandyaml_formatterhave an extra member when exceptions are off, so formatting in both kinds of code can overrun a formatter on the stack. With exceptions off, code that setsTOML_ENABLE_PARSER=0also disagrees with a compiled toml++ about their layout.- Nothing separates code built with compiler exceptions from code built without them. The parser's layout differs between the two even with
TOML_EXCEPTIONS=0in both.array::at()andtable::at()throw in one and assert in the other, and a program with both gets one behaviour everywhere, whateverTOML_EXCEPTIONSsays. - With exceptions off, the parser holds its error in an
optional, soTOML_OPTIONAL_TYPEchanges its layout too.
Separating these properly changes the layout or the exported names of the formatters and of at(), so it breaks the shared library's ABI.
at() without exceptions
toml::array::at() and toml::table::at() are the throwing alternatives to operator[] and get(). Built without compiler exceptions they can't throw, so an index or key that isn't there fails an assertion in debug builds and is undefined behaviour otherwise. v4 would leave these functions out when the compiler has exceptions off.
Code built without exceptions that calls at() would stop compiling.
Comparing date-times as instants
toml::date_time compares field by field. 1979-05-27T07:32:00Z and 1979-05-27T00:32:00-07:00 are the same instant but compare unequal, and < orders by local date and time before the offset. Offset date-times could compare as instants instead, with some rule for comparing them to local ones.
Equality of tables and arrays holding date-times would change with it, and so would the order of sorted containers of them.
Assigning a float to an integer value
toml::value<int64_t> takes the right-hand side of operator= as an int64_t, so v = 1.5 compiles and stores 1. The assignment could be deleted for floating-point operands, to match the comparisons, which don't truncate them.
Code that assigns a float to an integer value would stop compiling.
Deducing a value's type
toml::value{ x } deduces its type from x, and checks less than inserting x into a table or array does. Insertion rejects an initialiser of a type that the value type can't hold exactly, and the deduction guides accept it: toml::value{ uint64_t{ 1 } << 63 } is a toml::value<int64_t> holding INT64_MIN. The guides could be constrained as insertion is.
Code that relies on such a conversion would stop compiling.
Integer formats in value_flags
toml::value_flags is a flags enum, but its three integer formats are one two-bit field: binary is 1, octal is 2 and hexadecimal is 3. So flags & value_flags::format_as_binary is also non-zero for a hexadecimal value. The formats could have one bit each, or move to an enum of their own.
Both change the enumerators' values, and a separate enum changes the interface of toml::value as well.
Source regions of tables
For a table defined by a header, node::source() is the region of the header, and gives no position for the end of the table's contents. The region of an array of tables spans its first header to its last in the same way. Both could span their contents.
Code that reads the end of a table's region would get a different position.
Names kept for compatibility
format_flags::force_multiline_arrays is an undocumented alias of format_flags::force_multi_line_arrays, kept for code written against master before the rename. v4 would remove it.
TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA and TOML_DISABLE_NOEXCEPT_NOEXCEPT turn a feature off, where the library's other feature switches are named TOML_ENABLE_. v4 would rename them to match, with the defaults inverted.
TOML_INT_CHARCONV has no effect, because the library parses and prints integers without <charconv>. v4 would remove it.
Code that uses the alias would stop compiling. Code that sets one of the macros would lose the setting without a diagnostic.
Config macros
A TOML_ASSERT that the user defines is ignored when NDEBUG is defined, because the library then replaces it with a no-op. v4 could keep the user's definition in every build.
Some macros a user can set are escape hatches for compiler edge cases, and their documentation varies: several lack an entry in the API reference, a row in the README's table, or both. v4 would decide which of them are user interfaces, and document those the same way.
TOML_CALLCONV applies to every exported free function except impl::narrow() and impl::widen(), which v3.4.0 declares without it. v4 would apply it to them too.
Honouring TOML_ASSERT would turn assertions on in release builds that define it today. A DLL built with a non-default calling convention would export impl::narrow() and impl::widen() under new names.
Node storage
Parsing allocates once for every node, every table entry, every non-empty array, and every key or string too long for the small-string buffer. A parsed 8 MB document holds about 455,000 allocations, the fewest the current types allow. These would need fewer:
- tables as a sorted vector of key-value pairs, with one allocation per table where
std::mapmakes one per entry - tables and arrays holding their values in place, where each value is a separately allocated node today
- keys and strings that refer into one copy of the document
- one source path per document, where every node's source region holds a
std::shared_ptrto it today, and each copy is an atomic increment
Each changes the layout of a public type. The first two would also make inserting into a table or array invalidate references to its other elements, which stay valid today, and the third would change what toml::key and toml::value<std::string> hold.
A smaller node interface
toml::node has 35 virtual functions: the destructor, type(), twelve is_*() checks, eighteen as_*() casts and three is_homogeneous() overloads. So there are ten vtables of 38 entries, for node and its nine concrete types, and each concrete type has its own copy of every override, most of them a single return statement. In a program that parses and prints, they come to as much as 20 KB.
Only type() and is_homogeneous() need to be virtual. The checks and casts could be inline functions that test type(). That changes every node vtable and removes exported virtual functions, so it breaks the shared library's ABI.
Constructors that allocate under noexcept
The default and move constructors of toml::table and toml::array are noexcept. With the MSVC STL, std::map allocates in both of its own, and in debug builds std::vector does too, so running out of memory while constructing or moving a table calls std::terminate() where it could throw std::bad_alloc.
The constructors of toml::parse_error are noexcept too. With exceptions enabled they copy the message into storage that std::runtime_error allocates. The copy constructor of toml::value<std::string> is noexcept as well, and it copies the string.
Dropping the noexcept would let these constructors throw. Code that tests them with std::is_nothrow_* or noexcept() would see the change, and so would containers that move elements only when moving is noexcept.
Detecting _Float16
TOML_ENABLE_FLOAT16 defaults to 0, so _Float16 support is opt-in. Detecting it from the compiler's predefined __FLT16_* macros breaks GCC 7 to 12 on ARM, which define the macros in C++ without accepting the type there (#57, #178, #186). GCC 13 and newer, and Clang, define the macros only where they accept the type, so detection could be limited to them.
Turning it on by default would break code that sets TOML_SMALL_FLOAT_TYPE to _Float16, or to std::float16_t in C++23 with GCC, because the library would then define its traits for that type twice.
Minimum compiler versions
The library has workarounds for compilers that CI doesn't build with: GCC 7, and the classic Intel compiler, which Intel has retired. v4 could state a minimum version for each compiler and drop what is below it.
It also works around the legacy lambda processor, which MSVC uses before C++20 unless /Zc:lambda or /permissive- is given. Dropping that would make those builds pass one of the two options.
Anyone still building with one of those compilers would have to stay on v3.
Template machinery
The constraints and type traits are written for compilers where expression SFINAE and std::void_t detection are unreliable, so many of them are macros such as TOML_CONSTRAINED_TEMPLATE and long std::enable_if conditions. With newer minimum compilers they could be rewritten with detection idioms and if constexpr.
A rewrite could change which overload a call selects, and what a rejected call reports.
Internal macros
preprocessor.hpp defines macros that nothing in the library reads: the TOML_ARCH_ family, TOML_UNIX, TOML_LINUX, TOML_ICC_CL, TOML_COMPILER_HAS_RTTI, TOML_HAS_FEATURE, TOML_EMPTY_BASES, TOML_LIKELY_CASE and TOML_INLINE_GETTER. TOML_MAKE_FLAGS_1 takes an argument that its one caller leaves empty. Some of these are meant to be applied and aren't, TOML_EMPTY_BASES among them.
v4 would go over the whole set: apply each macro where it belongs, delete what has no use, and bring the definitions in line with the maintainer's other libraries.
None of them is a user interface, so no user code would change. Applying TOML_EMPTY_BASES could change the layout of a class with MSVC.
Formatter internals
The three formatters share a base class, and its layout is part of the ABI, so it can't gain a member in v3. Some state is therefore encoded in the members it has. toml_formatter uses an indent of -1 to mean "at the root of the
document", and has to undo that wherever it prints an array. A member for it would remove that code.
The constants that describe each format are exported too, so they can't gain a field for how strings are written. The JSON and YAML formatters therefore print strings themselves and bypass the shared code, and the YAML formatter does the same for floats.
A new member would change the layout of all three formatters.
Private members of exported classes
A Windows DLL build exports every member function of an exported class, private and inline ones included. v3 can't remove one or change its signature, so some internal helpers keep a form they no longer need: path_component::store_key() and store_index() are static and take the storage they write to as a parameter, and impl::formatter::stream() has one caller.
v4 could make the first two ordinary member functions and remove the third. No user code would change.
Unicode bare keys
With TOML_ENABLE_UNRELEASED_FEATURES, bare keys can hold the non-ASCII characters that toml-lang/
Documents that use such keys would stop parsing until the keys are quoted.
Lifetime annotations
A view or reference into a temporary table dangles at the end of the full expression. auto v = toml::parse(doc)["key"]; compiles without a warning, and leaves v pointing into a destroyed table.
Clang can warn about code like this if the library annotates itself: [[gsl::Owner]] on tables and arrays, [[gsl::Pointer]] on views, and [[clang::lifetimebound]] on the member functions that hand out views and references.
Such code would start to get warnings, which fails a build that treats warnings as errors.
Event interface
Parsing always builds the whole document as a tree of nodes. An event interface in the style of SAX would report each table, key and value as the parser reaches it, so a program could read a document without holding all of it in memory (#107).
Custom types
A user-defined type, such as a point with x and y members, has to be read and written one member at a time (#175). A conversion written once for each type could let value<T>() and value_or() return such a type, and let tables and arrays take one directly.
Reflection
With C++26 reflection, toml++ could convert between tables and structs without code written for each type (#324).
Output order and float precision
The formatters write a table's entries in key order, which is how toml::table stores them. Tables don't record the order their entries were inserted in. Floats are written with enough digits to read back as the same value, or rounded to at most six significant digits with format_flags::relaxed_float_precision. #304 asks for a choice of key order, insertion order included. It also asks for a way to set float precision, as std::setprecision does for a stream.
Writing in insertion order would need tables to record it, which changes their layout. Floats written with fewer digits than they need don't read back as the same values.
std::format support
Printing a node needs a std::ostream, with or without one of the formatters. Specialisations of std::formatter would let C++20 code pass nodes to std::format(), and C++23 code to std::print(), with a format specifier to pick TOML, JSON or YAML (#325).
CMake
Minimum CMake version
The minimum is CMake 3.14. Raising it to 3.21 would let project() set PROJECT_IS_TOP_LEVEL, so cmake/project-is-top-level.cmake could go. Copying runtime DLLs next to the Windows test executables would also stop needing a version check.
It would break anyone building with CMake 3.14 to 3.20, which includes the 3.16 that Ubuntu 20.04 ships.
Option names
The options use three naming styles. Most have a lowercase prefix, like tomlplusplus_INSTALL, tomlplusplus_BUILD_LIB and tomlplusplus_INSTALL_CMAKEDIR. TOMLPLUSPLUS_BUILD_MODULES is all uppercase, and BUILD_EXAMPLES and BUILD_FUZZER have no prefix. CMake convention is all uppercase, so every option would become TOMLPLUSPLUS_*.
Each renamed option breaks the scripts and recipes that set it, and one of them lives outside this repository. The OSS-Fuzz builder image copies fuzzing/build.sh from master, and CIFuzz runs master's copy against every pull request. BUILD_FUZZER has to keep working until master's script stops using it.
Package files for header-only installs
A header-only install puts the CMake package files in lib/cmake/tomlplusplus. They are the same on every architecture, so share/cmake/tomlplusplus suits them better, and Meson already uses it for header-only installs.
find_package() searches both locations. Anything that hard-codes the current path, such as a tomlplusplus_DIR setting, would break.
CPack
The top-level build includes CPack with no configuration, which adds a package target nobody has set up. Removing it takes that target away from anyone who runs it.
Meson
Version check
The tomlplusplusConfigVersion.cmake that Meson installs accepts any newer version, so find_package(tomlplusplus 2) finds 3.4. The one CMake installs only accepts the same major version, which matches the ABI namespace.
Making Meson's match would refuse version requests that succeed today.
Installed examples
With -Dbuild_examples=true, Meson installs the example programs into bin/. They exist to show the API, and the CMake build doesn't install them. Stopping it would remove files from installs that include them today.
Library type as a subproject
meson.build sets default_library=shared in its default_options. That is Meson's default anyway, so it only matters when toml++ is a subproject. There it overrides the parent project's default_library, and with Meson older than 1.8 it also overrides -Ddefault_library on the command line. Without it, the parent chooses.
Parent projects that build the library with build_lib=true and ask for static libraries would then get a static toml++, where they get a shared one today.
Repository
Tipi.build
The .tipi/ directory and the Tipi.build instructions in the README and on the main page support a package manager the project doesn't test against. Removing them would break Tipi users.
Appendix
Preserving comments
Parsing discards comments and whitespace, so a document that is read and written out again loses them. Keeping them properly needs a large rewrite, and partial support would be worse than none (#28, #312).
Table iteration by value
A toml::table iterator's proxy pair holds references to the key and the node, which keeps the std::unique_ptr that owns each node out of the API. So for (auto kv : tbl) copies two references, and generic code that asks for a copy expects a copy of the element (#31). It's the same proxy that breaks reverse iteration. Nodes held by value, for example as a discriminated union, would let tables do without it.