温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C++中怎么使用TS概念

发布时间:2021-11-24 11:11:25 来源:亿速云 阅读:189 作者:iii 栏目:大数据

本篇内容介绍了“C++中怎么使用TS概念”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

T.24:使用标签类或特征区分只有语义不同的概念

Reason(原因)

Two concepts requiring the same syntax but having different semantics leads to ambiguity unless the programmer differentiates them.

两个概念具有相同的语法需求但是语义不同会引起歧义,除非程序员可以区分它们。

Example (using TS concepts)(示例(使用TS概念))

template<typename I>    // iterator providing random access
concept bool RA_iter = ...;

template<typename I>    // iterator providing random access to contiguous data
concept bool Contiguous_iter =
   RA_iter<I> && is_contiguous<I>::value;  // using is_contiguous trait

The programmer (in a library) must define is_contiguous (a trait) appropriately.

程序员(在库代码中)必须恰当地定义is_contiguous(特征)。

Wrapping a tag class into a concept leads to a simpler expression of this idea:

将一个标签类封入概念可以更简单地表现想法。

template<typename I> concept Contiguous = is_contiguous<I>::value;

template<typename I>
concept bool Contiguous_iter = RA_iter<I> && Contiguous<I>;

The programmer (in a library) must define is_contiguous (a trait) appropriately.

程序员(在库代码中)必须恰当地定义is_contiguous(特征)。

Note(注意)

Traits can be trait classes or type traits. These can be user-defined or standard-library ones. Prefer the standard-library ones.

特征的表达可以通过特征类和类型特征给你来实现。它们可以是用户定义的,也可以由标准库提供。标准库提供的方式更好。

Enforcement(实施建议)

  • The compiler flags ambiguous use of identical concepts.

  • 编译器应该标记想定义完全相同的概念的混乱用法。

  • Flag the definition of identical concepts.

  • 标记完全相同的概念定义。

“C++中怎么使用TS概念”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

c++
AI