fix: use const char* instead of &char[N]

to enable to pass char*, not only string literal
This commit is contained in:
ToruNiina
2020-08-04 20:08:58 +09:00
parent 46e84a9cc2
commit 4fa94d45b3

View File

@@ -2089,17 +2089,16 @@ basic_value<Comment, Table, Array> parse(const std::string& fname)
// This function just forwards `parse("filename.toml")` to std::string version // This function just forwards `parse("filename.toml")` to std::string version
// to avoid the ambiguity in overload resolution. // to avoid the ambiguity in overload resolution.
// //
// Both std::string and std::filesystem::path are convertible from const char[]. // Both std::string and std::filesystem::path are convertible from const char*.
// Without this, both parse(std::string) and parse(std::filesystem::path) // Without this, both parse(std::string) and parse(std::filesystem::path)
// matches to parse("filename.toml"). This breaks the existing code. // matches to parse("filename.toml"). This breaks the existing code.
// //
// This function exactly matches to the invokation with string literal. // This function exactly matches to the invokation with c-string.
// So this function is preferred than others and the ambiguity disappears. // So this function is preferred than others and the ambiguity disappears.
template<typename Comment = ::toml::discard_comments, template<typename Comment = ::toml::discard_comments,
template<typename ...> class Table = std::unordered_map, template<typename ...> class Table = std::unordered_map,
template<typename ...> class Array = std::vector, template<typename ...> class Array = std::vector>
std::size_t N> basic_value<Comment, Table, Array> parse(const char* fname)
basic_value<Comment, Table, Array> parse(const char (&fname)[N])
{ {
return parse<Comment, Table, Array>(std::string(fname)); return parse<Comment, Table, Array>(std::string(fname));
} }