VS2019中的C++20 chrono解析问题(最新)

And*_*rew 8 c++ date c++-chrono c++20

我有一个使用 date.h 库在 C++14 下工作的函数,但我正在将程序转换为使用 C++20,但它不再工作。请问我做错了什么?

我的C++14/date.h代码如下:

#include <date/date.h> // latest, installed via vcpkg
#include <chrono>

auto StringToUnix(const std::string& source) -> std::time_t
{
    auto in = std::istringstream(source);
    auto tp = date::sys_seconds{};
    in >> date::parse("%Y-%m-%d %H:%M:%S", tp); 

    return std::chrono::system_clock::to_time_t(tp);
}
Run Code Online (Sandbox Code Playgroud)

我转换后的C++20函数如下:

#include <chrono>

auto StringToUnix(const std::string& source) -> std::time_t
{
    using namespace std::chrono;
    auto in = std::istringstream(source);
    auto tp = sys_seconds{};
    in >> parse("%Y-%m-%d %H:%M:%S", tp);

    return system_clock::to_time_t(tp);
}
Run Code Online (Sandbox Code Playgroud)

我在 VS2019 社区(最新)中收到的错误是:

E0304   no instance of overloaded function "parse" matches the argument list    
Run Code Online (Sandbox Code Playgroud)

是否有任何细微的变化是我遗漏的?请问是什么原因导致这个错误?

How*_*ant 12

规范中有一个错误正在修复中。VS2019忠实地再现了该规范。将格式字符串包装在 中string{},或者给它一个尾随s文字以将其转换为字符串,这将解决该错误。

in >> parse("%Y-%m-%d %H:%M:%S"s, tp);
Run Code Online (Sandbox Code Playgroud)