在哥德波特,有一个名为"x86-64 clang (实验概念)“的clang版本,提供了实验性的核心语言概念特性。
是否也有一种方法来使用(一个实验性版本的)标准库实现?
在设计概念时,有std::convertible_to和朋友将是很好的。
发布于 2020-03-08 21:04:44
在我看来,GCC在实现C++20特性方面似乎领先了一点。使用GCC (主干)运行以下代码的你可以上网查:
#include <iostream>
#include <concepts>
template<typename T> concept scalar = std::is_scalar_v<T>;
template<typename T>
class Foo
{
public:
Foo(T t) requires scalar<T>: _t{t} { std::cout << "is scalar" <<std::endl; }
Foo(T t) requires (not scalar<T>): _t{t} { std::cout << "is not scalar" <<std::endl;}
private:
T _t;
};
class cls {};
int main()
{
Foo{true};
Foo{'d'};
Foo{3.14159};
cls c;
Foo{c};
return 0;
}https://stackoverflow.com/questions/60421231
复制相似问题