您好,登錄后才能下訂單哦!
這篇文章主要介紹“C++怎么為概念定義公理”,在日常操作中,相信很多人在C++怎么為概念定義公理問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C++怎么為概念定義公理”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
T.22:為概念定義公理
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.
有意義/有用的概念會包含語義上的含義。以非正規(guī)的,半正規(guī)的或者正規(guī)的方式進行表現(xiàn)這些語義可以讓概念更容易被用戶理解,而且表達概念的努力可以捕捉概念方面的錯誤。定義語義是一種有力的設(shè)計工具。
Example (using TS concepts)(示例(適用TS概念))
template<typename T>
// 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;
}
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).
這是一條有關(guān)數(shù)學規(guī)律的公理:某些不需要證據(jù)的假設(shè)。通常,公理是不可證明的,即使它們可以證明,通常也會超越編譯器的能力。公理可能并不普遍,但是模板作者可以假設(shè)它對所有實際使用的輸入有效(類似前提條件)
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),因此我們必須在很長一段時間將它放在注釋內(nèi)。一旦語言提供了對公理的支持,就可以去掉前面的//。
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:
仍在開發(fā)中的新“概念”的早期版本通常只是定義某些約束的簡單集合,而這些約束可能并不具有良好定義的語義。發(fā)現(xiàn)完美的語義需要努力和時間。約束的不完全集合同樣可以非常有用。
// balancer for a generic binary tree
template<typename Node> 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.
因此樹節(jié)點上的Balancer必須至少支持三個操作,但是我們還沒有準備好定義語義的細節(jié),因為新種類的平衡樹可能需要更多的操作,而且適用于所有節(jié)點的準確、通用的語義很難在設(shè)計的早期階段確定。
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.
不完全或者沒有良好定義的“概念”仍然有用。例如,它允許在初始化階段進行某些檢查。然而,它不應(yīng)該被認定是穩(wěn)定的。每一次新用法都可能讓這個不完全的概念發(fā)生改變。
Enforcement(實施建議)
Look for the word "axiom" in concept definition comments
在概念定義的注釋中發(fā)現(xiàn)”axiom“。
到此,關(guān)于“C++怎么為概念定義公理”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。