Visual studio 2019 c++ support of concepts - compiles successfully with error: Why?

Visual studio 2019 c++ support of concepts - compiles successfully with error: Why?

我已经安装了最新版本的 visual studio 来测试概念。我尝试例如:

struct One{};
struct Two{
    std::string ToString() const
    {
        return "BAM!";
    }
};

template<typename T>
concept hasToString = requires(T t) { t.ToString(); };

template <class T>
void DoString(T& t)
{
    if constexpr (hasToString<T>)
    {
        std::cout << t.ToString() << std::endl;
    }
    else
    {
       std::cout << "not available" << std::endl;
    }
}

int main(int argc, char** argv)
{
    One one{};
    Two two{};
    DoString(one);
    DoString(two);
    return 0;
}

这会编译(使用 /std::c++latest),并给出我预期的输出:

not available
BAM!

但是,visual studio community c++ 16.5.0 给出了 1 个错误(即使它完成了编译):

标识符 "concept" 未定义

我不知道为什么?根据下面post,应该支持概念。

https://devblogs.microsoft.com/cppblog/c20-concepts-are-here-in-visual-studio-2019-version-16-3/

我是不是做错了什么?什么?或者是这个错误,如果是,有没有办法在 MS 修复错误之前抑制错误?

您描述的错误来自 Intellisense,该引擎会在您键入时在代码编辑器中显示红色波浪线(并填充 "live" 错误列表作为你发展)。

尽管这是在编译您的代码,但实际上它使用的引擎与实际构建您的项目并生成可执行文件的引擎不同。

根据 the feature announcement you linked to,它还不是最新的(对于一个全新的功能来说并不离谱):

IntelliSense support is not currently available

忽略。