diff --git a/toml/parser.hpp b/toml/parser.hpp index b2e4755..d919c16 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -2102,6 +2102,24 @@ basic_value parse(const std::string& fname) } #ifdef TOML11_HAS_STD_FILESYSTEM +// This function just forwards `parse("filename.toml")` to std::string version +// to avoid the ambiguity in overload resolution. +// +// Both std::string and std::filesystem::path are convertible from const char[]. +// Without this, both parse(std::string) and parse(std::filesystem::path) +// matches to parse("filename.toml"). This breaks the existing code. +// +// This function exactly matches to the invokation with string literal. +// So this function is preferred than others and the ambiguity disappears. +template class Table = std::unordered_map, + template class Array = std::vector, + std::size_t N> +basic_value parse(const char (&fname)[N]) +{ + return parse(std::string(fname)); +} + template class Table = std::unordered_map, template class Array = std::vector>