千家信息网

C++怎么为概念定义公理

发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,这篇文章主要介绍"C++怎么为概念定义公理",在日常操作中,相信很多人在C++怎么为概念定义公理问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"C++怎么为概念定义公理"
千家信息网最后更新 2025年12月03日C++怎么为概念定义公理

这篇文章主要介绍"C++怎么为概念定义公理",在日常操作中,相信很多人在C++怎么为概念定义公理问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"C++怎么为概念定义公理"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

T.22:为概念定义公理

Reason(原因)

A meaningful/useful concept has a semantic meaning. Expressing these semantics in an informal, semi-formal, or formal way makes the concept comprehensible to readers and the effort to express it can catch conceptual errors. Specifying semantics is a powerful design tool.

有意义/有用的概念会包含语义上的含义。以非正规的,半正规的或者正规的方式进行表现这些语义可以让概念更容易被用户理解,而且表达概念的努力可以捕捉概念方面的错误。定义语义是一种有力的设计工具。

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

template
// The operators +, -, *, and / for a number are assumed to follow the usual mathematical rules
// axiom(T a, T b) { a + b == b + a; a - a == 0; a * (b + c) == a * b + a * c; /*...*/ }
concept Number = requires(T a, T b) {
{a + b} -> T; // the result of a + b is convertible to T
{a - b} -> T;
{a * b} -> T;
{a / b} -> T;
}
Note(注意)

This is an axiom in the mathematical sense: something that may be assumed without proof. In general, axioms are not provable, and when they are the proof is often beyond the capability of a compiler. An axiom may not be general, but the template writer may assume that it holds for all inputs actually used (similar to a precondition).

这是一条有关数学规律的公理:某些不需要证据的假设。通常,公理是不可证明的,即使它们可以证明,通常也会超越编译器的能力。公理可能并不普遍,但是模板作者可以假设它对所有实际使用的输入有效(类似前提条件)

Note(注意)

In this context axioms are Boolean expressions. See the Palo Alto TR for examples. Currently, C++ does not support axioms (even the ISO Concepts TS), so we have to make do with comments for a longish while. Once language support is available, the // in front of the axiom can be removed

在这个上下文中公理是一个布尔类型的表达式。参见Palo Alto TR中的例子。目前C++还没有支持公理(包括ISO Concepts TS),因此我们必须在很长一段时间将它放在注释内。一旦语言提供了对公理的支持,就可以去掉前面的//。

Note(注意)

The GSL concepts have well-defined semantics; see the Palo Alto TR and the Ranges TS.

GSL概念提供了定义良好的语义。参见Palo Alto TR和范围TS。

Exception (using TS concepts)(例外(使用TS概念))

Early versions of a new "concept" still under development will often just define simple sets of constraints without a well-specified semantics. Finding good semantics can take effort and time. An incomplete set of constraints can still be very useful:

仍在开发中的新"概念"的早期版本通常只是定义某些约束的简单集合,而这些约束可能并不具有良好定义的语义。发现完美的语义需要努力和时间。约束的不完全集合同样可以非常有用。

// balancer for a generic binary tree
template concept bool Balancer = requires(Node* p) {
add_fixup(p);
touch(p);
detach(p);
}

So a Balancer must supply at least thee operations on a tree Node, but we are not yet ready to specify detailed semantics because a new kind of balanced tree might require more operations and the precise general semantics for all nodes is hard to pin down in the early stages of design.

因此树节点上的Balancer必须至少支持三个操作,但是我们还没有准备好定义语义的细节,因为新种类的平衡树可能需要更多的操作,而且适用于所有节点的准确、通用的语义很难在设计的早期阶段确定。

A "concept" that is incomplete or without a well-specified semantics can still be useful. For example, it allows for some checking during initial experimentation. However, it should not be assumed to be stable. Each new use case may require such an incomplete concept to be improved.

不完全或者没有良好定义的"概念"仍然有用。例如,它允许在初始化阶段进行某些检查。然而,它不应该被认定是稳定的。每一次新用法都可能让这个不完全的概念发生改变。

Enforcement(实施建议)

  • Look for the word "axiom" in concept definition comments

  • 在概念定义的注释中发现"axiom"。

到此,关于"C++怎么为概念定义公理"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

概念 语义 C++ 学习 良好 更多 有用 支持 正规 时间 注释 节点 阶段 帮助 设计 有效 接下来 三个 上下 上下文 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 西安夏佩互联网科技有限公司 登陆linux服务器 战地1被踢出服务器后什么界面 学校网络安全教育活动资料 数据库建立索引多了的坏处 笔记本搭建手游服务器 数据库自动化运维平台 我的世界有抽奖机的服务器推荐 云南综合软件开发市场价 七星关网络安全知识有奖竞答 dw数据库怎么建 广电网络技术中心述职报告 什么文化能学习软件开发 宁波大学网络技术与工程 300大作战服务器优化了吗 我的世界pe服务器刷东西bug 计算机应用及网络技术好就业吗 山东航空软件开发工资 从哪发掘想做软件开发的客户 旧电脑建设服务器 网络安全适合女生用的网络 一般服务器支持多少路人脸识别 梦幻西游转服务器转移不去 查看数据库中的某个字段值 大商天狗软件开发待遇 广西会计软件开发创新服务 北京网络安全公司女总经理 泰坦陨落北极星服务器教程 数据库技术与应用 mysql 昆特牌数据库
0