Merge pull request #189 from muggenhor/fix/avoid-fname-copy

fix: don't force a copy of std::string fname when moving is an option
This commit is contained in:
Toru Niina 2022-06-04 20:49:33 +09:00 committed by GitHub
commit 6d9e533cf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2317,7 +2317,7 @@ template<typename Comment = TOML11_DEFAULT_COMMENT_STRATEGY,
template<typename ...> class Table = std::unordered_map,
template<typename ...> class Array = std::vector>
basic_value<Comment, Table, Array>
parse(std::istream& is, const std::string& fname = "unknown file")
parse(std::istream& is, std::string fname = "unknown file")
{
using value_type = basic_value<Comment, Table, Array>;
@ -2372,14 +2372,14 @@ parse(std::istream& is, const std::string& fname = "unknown file")
template<typename Comment = TOML11_DEFAULT_COMMENT_STRATEGY,
template<typename ...> class Table = std::unordered_map,
template<typename ...> class Array = std::vector>
basic_value<Comment, Table, Array> parse(const std::string& fname)
basic_value<Comment, Table, Array> parse(std::string fname)
{
std::ifstream ifs(fname.c_str(), std::ios_base::binary);
if(!ifs.good())
{
throw std::runtime_error("toml::parse: file open error -> " + fname);
}
return parse<Comment, Table, Array>(ifs, fname);
return parse<Comment, Table, Array>(ifs, std::move(fname));
}
#ifdef TOML11_HAS_STD_FILESYSTEM