【发布时间】:2021-11-14 13:13:25
【问题描述】:
如果有人能解释 C++ 20+ 编译器(在我的例子中是 MSVC 2022)如何编译以下内容,我将不胜感激,为什么 Simple 概念没有效果?
template <typename T>
concept Simple = requires(T t)
{
std::is_trivial_v<T> == true;
};
void foo(Simple auto s) {
std::cout << "bar";
}
int main(int argc, char** argv)
{
using Bytes = std::span<std::byte>;
Bytes b;
static_assert(false == std::is_trivial_v<Bytes>);
foo(b); //compiles and prints "bar"
}
【问题讨论】:
-
您希望得到什么?编译器是否应该停止并显示警告或错误消息?
-
@OlafDietsche 我原以为它会因错误而停止,但 HolyBlackCat 解释说我没有测试我认为的内容