首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >任何使用标准库#包括<concepts>和clang的机会

任何使用标准库#包括<concepts>和clang的机会
EN

Stack Overflow用户
提问于 2020-02-26 19:33:50
回答 1查看 442关注 0票数 0

哥德波特,有一个名为"x86-64 clang (实验概念)“的clang版本,提供了实验性的核心语言概念特性。

是否也有一种方法来使用(一个实验性版本的)标准库实现?

在设计概念时,有std::convertible_to和朋友将是很好的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-08 21:04:44

在我看来,GCC在实现C++20特性方面似乎领先了一点。使用GCC (主干)运行以下代码的你可以上网查

代码语言:javascript
复制
#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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60421231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档