5

From what I remember C++ has concepts such as Mergable, Container, Comparable, Sortable, Arithmetic etc. I seen them here and there but I never seen a list. Where can I find a list of standard C++ concepts?

-edit- people are confused but what I mean is the example template line in this slide which has Container and Sortable. What else is there?

4

3 回答 3

9

根据我的记忆,C++ 有诸如 Mergable、Container、Comparable、Sortable、Arithmetic 等概念。我到处看到它们,但我从未见过列表。在哪里可以找到标准 C++ 概念的列表?

什么是概念

概念是一个术语,指的是编译器必须强制执行的类型要求的形式化。该草案(N3580) 包含所有详细信息。

什么是类型要求

类型要求是一组要求,即使在 C++03 标准中也定义,必须由程序员强制执行,以便对所述类型应用一些操作。该标准从不称它们为概念

类型要求列表

我认为您的意思是类型要求,因为:

  • 你提到Container
  • 你提到Comparable
  • 你记得C++ 有“概念”这一事实

因此,这里是类型要求列表,您还可以在其中找到ContainerCompare(由cppreference组织):

基本的

  • DefaultConstructible
  • 可移动构造
  • 可复制构造
  • 移动可分配
  • CopyAssignable
  • 可破坏的

布局

  • 可轻松复制
  • 琐碎类型
  • 标准布局类型
  • POD 类型

图书馆范围内

  • 平等可比
  • 小于可比
  • 可交换
  • 价值交换
  • 可空指针
  • 哈希
  • 分配器
  • 函数对象
  • 可调用
  • 谓词
  • 二元谓词
  • 相比

容器

  • 容器
  • 可逆容器
  • 分配器感知容器
  • 序列容器
  • 关联容器
  • 无序关联容器

容器元素

  • 复制可插入
  • 移动可插入
  • EmplaceConstructible

迭代器

  • 迭代器
  • 输入迭代器
  • 输出迭代器
  • 前向迭代器
  • 双向迭代器
  • 随机存取迭代器

流 I/O 函数

  • 无格式输入函数
  • 格式化输入函数
  • 无格式输出函数
  • 格式化输出函数

随机数发生器

  • 种子序列
  • 统一随机数生成器
  • 随机数引擎
  • 随机数引擎适配器
  • 随机数分布

并发

  • 基本可锁定
  • 可锁定
  • 可定时锁定
  • 互斥体
  • 定时互斥
  • SharedTimedMutex

其他

  • 一元类型特征
  • BinaryTypeTrait
  • 转化特征
  • 琐碎时钟
  • 字符特征
  • pos_type
  • 关闭类型
  • 位掩码类型
  • 文字类型
于 2014-06-15T12:17:08.127 回答
4

Where can I find a list of standard C++ concepts?

Apparently, there isn't any, it didn't make it to the standard yet; see also Is the Committee Draft of Standard C++14 public? Nevertheless, the relevant documents seem to be Concepts Lite: Constraining Templates with Predicates (N3580) and A Concept Design for the STL (N3351). The list, as of Jun 15, 2014, taken from N3580:

Type Traits

  • Equality_comparable
  • Totally_ordered
  • Movable
  • Copyable
  • Semiregular
  • Regular
  • Function
  • Regular_function
  • Predicate
  • Relation

Iterator Concepts

  • Iterator_category
  • Value_type
  • Difference_type
  • Readable
  • Writable
  • Permutable
  • Mutable
  • Advanceable
  • Incrementable
  • Input_iterator
  • Output_iterator
  • Forward_iterator
  • Bidirectional_iterator
  • Random_access_itertor

Algorithm Constraints

  • Indirectly_movable
  • Indirectly_copyable
  • Indirectly_swappable
  • Indirectly_equal
  • Indirectly_ordered
  • Indirectly_comparable
  • Sortable
  • Mergeable
于 2014-06-15T11:43:03.450 回答
1

简而言之,“概念”是由有效表达式、关联类型、不变量和复杂性保证组成的一组要求。满足要求的类型称为对该概念进行建模。一个概念可以扩展另一个概念的要求,称为细化。”

来源: http: //www.boost.org/community/generic_programming.html#concept

有几个可用的概念列表:

如需进一步解释,请参阅以下“概念和建模”以及“细化”: https ://www.sgi.com/tech/stl/stl_introduction.html

也可以看看:

您也可能对。。。有兴趣:

于 2014-06-15T15:03:14.673 回答