任何机会使用标准库 #include <concepts> with clang

Any chance to use standard library #include <concepts> with clang

godbolt 有一个 clang 版本叫做 "x86-64 clang (experimental concepts)",提供实验性核心语言概念功能。

是否还有一种方法可以使用标准库实现(的实验版本)?

如果在设计概念时有 std::convertible_to 和朋友在场就好了。

在我看来,GCC 在实现 C++20 功能方面要领先一些。 You can check online 以下代码使用 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;
}