五月26日是什么星座| 又什么又什么的草地| 丙氨酸氨基转移酶偏高吃什么药| 柯基犬为什么要断尾巴| 面料支数是什么意思| 什么因果才会有双胞胎| 阳痿早泄挂什么科| 事急从权是什么意思| 活动性肺结核是什么意思| 医学上pi是什么意思| 梦见大蟒蛇是什么预兆| 描红是什么意思| 刮痧用什么油刮最好| 早起胃疼是什么原因导致的| 四叶草的寓意是什么| 枭雄的意思是什么| 高锰酸钾有什么作用| 中老年人喝什么奶粉好| 二月十九是什么星座| 城镇户口是什么意思| 登高是什么意思| ph值什么意思| 血清铁蛋白高是什么原因| 十六年是什么婚| 什么是文字狱| 百合什么时候种植最好| 催丹香是什么意思| 头昏挂什么科| 脾胃湿热吃什么药| 冷战的男人是什么心理| 什么的叶丛| 头疼挂什么科| 摘帽是什么意思| 射精快吃什么药| 梦见性生活是什么意思| 喉咙痒咳嗽是什么原因| 娘酒是什么酒| 什么是理数| 女性外阴瘙痒用什么药| 堤防是什么意思| 宝宝说话晚是什么原因造成的| 为什么感冒会咳嗽| 什么药消肿最快最有效| 6个月宝宝可以吃什么水果| 广西三月三是什么节日| 痢疾是什么意思| 生物公司是做什么的| 三月29号是什么星座| 咽干是什么原因造成的| 未曾谋面什么意思| 老虎五行属什么| 转氨酶高是什么原因造成的| 火碱对人体有什么害处| 猫咪的胡须有什么作用| 哥文花园女装什么档次| 心率过快有什么危害| 八月十七是什么星座| 多发性脂肪瘤是什么原因造成的| 心存芥蒂是什么意思| 北京市市长是什么级别| 脚踝扭伤挂什么科| 更是什么结构的字| 中药什么时间喝效果最好| 水色是什么颜色| 做梦捡到钱是什么意思| 为什么总是想吐| 双肺纹理增多增粗是什么意思| 沁人心扉什么意思| 为什么会得面瘫| h1是什么意思| 中国四大发明是什么| 高氨血症是什么病| 从什么不什么四字词语| 乖乖是什么意思| 女人梦见猪是什么预兆| 杵状指见于什么疾病| 小孩上火吃什么药| 甲状腺滤泡性肿瘤是什么意思| 鲨鱼为什么不吃海豚| 1956年是什么年| notebook是什么意思| 草字头加果念什么| 小孩出汗多是什么原因| 鸡同鸭讲是什么意思| 手抖是因为什么| 18年是什么婚| 佝偻病什么症状| 脑硬化是什么病严重吗| 湿热内蕴证有什么症状| 香港为什么叫香港| 牛鞭是牛的什么部位| 美帝什么意思| 耳聋是什么原因引起的| 鬼佬是什么意思| 检查喉咙挂什么科| 物欲横流什么意思| 女生是t是什么意思| 大便发黑是什么情况| 心电图异常q波是什么意思| 宫颈糜烂是什么原因引起的| 承欢膝下什么意思| 剖腹产坐月子可以吃什么水果| 什么是三重一大事项| 肝实质密度减低是什么意思| 舌系带挂什么科| 结肠炎吃什么中成药| 鸽子配什么煲汤最好| 睡不着有什么好办法吗| 房颤吃什么药好| 佛口蛇心是什么生肖| 疖肿吃什么药| 多梦睡眠质量不好是什么原因| 优点是什么意思| 12月是什么月| 缘木求鱼是什么意思| 三基色是什么颜色| 疏忽是什么意思| 蛋白高是什么原因| dq是什么意思| 菠菜什么时候种最合适| 柿子什么季节成熟| 淋巴结看什么科| 胆结石有什么症状| 5月8日是什么星座| 睡眠障碍挂什么科| 彻底是什么意思| 感冒吃什么药| 白带带血丝是什么原因| 母后是什么意思| 为什么长白头发| 08年属什么生肖| model是什么品牌| 鼻梁痛什么原因引起的| 老年人反复发烧是什么原因引起的| k金是什么金| 流黄鼻涕吃什么药| 全身痒是什么病| 小腿疼痛挂什么科| 盗窃是什么意思| 股骨头坏死是什么原因引起的| 4级残疾证有什么优惠政策| 萎缩性胃炎什么意思| 穿什么衣服| 心魔是什么意思| 仓鼠为什么喜欢跑轮| 姓黑的都是什么族| 画什么才好看| 耳石症吃什么药最好| 第一胎打掉会有什么影响| 乌龟和甲鱼有什么区别| 牙齿上有黑点是什么原因| 老虎下山下一句是什么| 子宫肥大有什么危害| 肾病可以吃什么水果| 为什么积食发烧很难退| 帆状胎盘是什么意思| 脑子里嗡嗡响是什么原因| gtp什么意思| 阴道有腥味是什么原因| 狗狗胰腺炎有什么症状| 鼻子上火是什么原因引起的| 为什么经常刷牙还牙黄| 尿胆原norm是什么意思| hl是什么意思| 痹是什么意思| 断流什么意思| 叛逆期是什么意思| 良字少一点是什么字| 春节是什么时候| 为什么会梦遗| 过敏去医院挂什么科| 感冒低烧吃什么药| 宫保鸡丁属于什么菜系| 什么时候补钙最佳时间| 九月初四是什么星座| 淋巴在什么部位| 日前是什么意思| 顶格是什么意思| 放浪形骸是什么意思| 心脏房颤是什么原因| 护肝养肝吃什么药最好| 郁结是什么意思| 下午四五点是什么时辰| 痛风能吃什么菜| 子午相冲是什么生肖| ipadair2什么时候上市的| 温州人为什么会做生意| 年年有今日岁岁有今朝什么意思| 心口疼吃什么药| 胸部疼痛挂什么科| 急性喉炎吃什么药| 彩超挂什么科| 心脏不舒服挂什么科室| 忠武路演员是什么意思| 风疹是什么原因引起的| 防晒衣什么材质最防晒| 心肌炎挂什么科| 背信弃义是什么意思| 硬不起吃什么药| 宝宝干呕是什么原因| 摆架子是什么意思| 双侧肋膈角锐利是什么意思| 晚上10点是什么时辰| 认知障碍是什么意思| 龟苓膏有什么功效| 北海龙王叫什么| 支气管炎咳嗽吃什么药好得快| 12月26日什么星座| 西瓜有什么功效和作用| 葡萄糖粉适合什么人喝| 玛卡和什么搭配壮阳效果最佳| mt是什么单位| 牛与什么生肖最配| 刚拔完牙需要注意什么| 一模一样的意思是什么| 小便带血是什么原因| 月经不调吃什么药调理最好| 捉虫是什么意思| 做梦数钱是什么意思啊| 什么时候做人流才是最佳时间| 小便尿血是什么原因| 王加玉念什么| 佛法的真谛是什么| o型血为什么招蚊子| 头晕目眩是什么原因| wl是什么意思| 狗狗吃南瓜有什么好处| 阴阳两虚吃什么药最好| s是什么m是什么| 什么奶粉好吸收好消化| 早上吃什么| 中性粒细胞绝对值偏高是什么原因| 膀胱炎挂什么科| 11月27日是什么星座| 特点是什么意思| 今年温度为什么这么高| pmi是什么| 食道不舒服挂什么科| 吃什么头发长的快| 老人生日送什么礼物好| s是什么牌子| 老人出汗多是什么原因| 星期天左眼皮跳是什么预兆| 湿气太重吃什么药最好| 女性私处长痘痘是什么原因| 为什么地球是圆的| 为什么会胃酸反流| 颜控什么意思| 女性腋臭什么年龄消失| 三月一日是什么星座| 手指甲软薄是缺什么| 霍金得了什么病| apc是什么意思| 出家当和尚有什么要求| 总胆固醇偏高吃什么药| 鱼爱吃什么食物| 怀挺是什么意思| 蜂蜜有什么好处| 什么时候恢复的高考| 昆仑玉是什么玉| 地图舌吃什么药| 吃什么食物可以降尿酸| 孩子为什么有胎记| g18k金是什么意思| 百度Jump to content

公安部交管局:2015年上半年全国新增机动车7

From Wikipedia, the free encyclopedia
百度 我觉得它表现很好,首先部队飞行员非常喜欢,喜欢是从内心里喜欢。

Concepts are an extension to the templates feature provided by the C++ programming language. Concepts are named Boolean predicates on template parameters, evaluated at compile time. A concept may be associated with a template (class template, function template, member function of a class template, variable template, or alias template), in which case it serves as a constraint: it limits the set of arguments that are accepted as template parameters.

Originally dating back to suggestions for C++11, the original concepts specification has been revised multiple times before formally being a required part of C++20.

Main uses

[edit]

The main uses of concepts are:

  • introducing type-checking to template programming
  • simplified compiler diagnostics for failed template instantiations
  • selecting function template overloads and class template specializations based on type properties
  • constraining automatic type deduction

Constraint types and usage

[edit]

There are five different places in a function template signature where a constraint can be used (labeled below as C1 to C5):[1]

template<C1 T>
requires C2<T>
C3 auto Fun(C4 auto param) requires C5<T>;
  • C1: A type-constraint. This kind replaces class or typename for declaring a type template parameter. When using a concept instead of the former two the type is constraint.
  • C2: A requires-clause. Whenever a type-constraint does not work, for example, because the concept takes multiple parameters, a requires-clause can be used to apply more elaborated constraints.
  • C3 / C4: A constrained placeholder type. The same syntax is available for placeholder variable aka. auto variable. C++20 added abbreviated function templates which use auto as a placeholder type in the parameter declaration.[2] A constrained placeholder type allows to put constraints on the automatically deduced return type of a function or a variable.
  • C5: A trailing requires-clause. This form is similar to C2 with one notable exception. A trailing requires-clause can be applied to a function in a class template. This allows the function to remain a regular, template-free function, which can be enabled or disabled depending on the functions trailing requires-clause.

The constraint forms C1 and C2 can be used in all kinds of templates.

Example: equality_comparable

[edit]

The following is a declaration of the concept "equality_comparable" from the <concepts> header of a C++20 standard library. This concept is satisfied by any type T such that for lvalues a and b of type T, the expressions a==b and a!=b as well as the reverse b==a and b!=a compile, and their results are convertible to a type that satisfies the concept "boolean-testable":

// The following concept is an implementation detail used to build equality_comparable
template<typename T, typename U>
concept weakly_equality_comparable_with = requires(const remove_reference<T>& a, const remove_reference<U>& b) {
    { a == b } -> std::same_as<bool>;
    { a != b } -> std::same_as<bool>;
    { b == a } -> std::same_as<bool>;
    { b != a } -> std::same_as<bool>;
};

template<class T>
concept equality_comparable = weakly_equality_comparable_with<T, T>;

A function template constrained on this concept may be declared as follows:

void f(const equality_comparable auto&); // constrained abbreviated function template declaration using a constrained placeholder type (C4 from above)

or

template <equality_comparable T>
void f(const T&); // constrained function template declaration using a type constraint (C1 from above)

And may be called as usual:

f(42); // OK, int satisfies equality_comparable

Compiler diagnostics

[edit]

If a programmer attempts to use a template argument that does not satisfy the requirements of the template, the compiler will generate an error. When concepts are not used, such errors are often difficult to understand because the error is not reported in the context of the call, but rather in an internal, often deeply nested, implementation context where the type was used.

For example, std::sort requires that its first two arguments be random-access iterators. If an argument is not an iterator, or is an iterator of a different category, an error will occur when std::sort attempts to use its parameters as bidirectional iterators:

// std::list is typically a doubly-linked list, whose iterators are not random-access
std::list<int> l = {2, 1, 3};
std::sort(l.begin(), l.end());

Typical compiler diagnostic without concepts is over 50 lines of output, beginning with a failure to compile an expression that attempts to subtract two iterators:

In instantiation of 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
 error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::_List_iterator<int>')
 std::__lg(__last - __first) * 2,

[..]

If concepts are used, the error can be detected and reported in the context of the call:

error: cannot call function 'void std::sort(_RAIter, _RAIter) [with _RAIter = std::_List_iterator<int>]'
note:   concept 'RandomAccessIterator()' was not satisfied

Overload resolution

[edit]

Concepts can be used to choose function template overloads and class template specializations based on properties of their template arguments, as an alternative to SFINAE and tag dispatching. If an argument satisfies more than one concept, the overload associated with the more constrained concept is chosen.

Type deduction

[edit]

Concepts may be used instead of the unconstrained type deduction placeholder auto in variable declarations and function return types:

auto     x1 = f(y); // the type of x1 is deduced to whatever f returns
Sortable auto x2 = f(y); // the type of x2 is deduced, but only compiles if it satisfies Sortable

Implementation status

[edit]

Concepts TS, as specified in ISO/IEC TS 19217:2015, are implemented as an experimental feature in GCC 6.[3] C++20 concepts are fully implemented in GCC 10,[4] MSVC 19.30,[5] and Clang 10.[6]

History

[edit]

A different form of Concepts, popularly known as "C++0x Concepts", was temporarily accepted into the working paper for C++11 but was removed in 2009.[7] In addition to concepts themselves, "C++0x Concepts" included concept maps (a feature that could make it possible, for example, for the concept "Stack" to accept std::vector, automatically mapping "Stack" operations such as push() to differently named operations on std::vector, such as push_back()) and axioms (a facility to specify semantic properties such as associativity or commutativity, allowing the compiler to take advantage of these properties without proof).

In contrast to this abandoned proposal, the C++20 version of Concepts is sometimes referred to as "Concepts Lite".[8]

During the C++ standards committee meeting in March 2016, the evolution working group moved to merge Concepts into the mainline C++17 standard, but the motion was defeated in full committee.[9]

Concepts v1 was merged into the C++20 draft.[10]

"The One Range" version of Range feature that depend on concepts was also merged into C++20.

See also

[edit]

Notes

[edit]
  1. ^ Fertig, Andreas (2021). Programming with C++20. Fertig Publications. p. 23. ISBN 978-3-949323-01-0.
  2. ^ "ISO/IEC 14882:2020". ISO. December 2020. Retrieved 14 July 2022.
  3. ^ "GCC 6 Release Series - Changes, New Features, and Fixes".
  4. ^ "C++ compiler support (gcc)".
  5. ^ "C++ compiler support".
  6. ^ "C++ Support in Clang".
  7. ^ Bjarne Stroustrup (22 July 2009). "The C++0x "Remove Concepts" Decision". Dr. Dobbs.
  8. ^ Andrew Sutton (24 February 2013). "Concepts Lite: Constraining Templates with Predicates". isocpp.org.
  9. ^ Honermann, Tom (6 March 2016). "Why Concepts didn't make C++17". honermann.net. Archived from the original on 2 October 2018. Retrieved 19 April 2016.
  10. ^ "2017 Toronto ISO C++ Committee Discussion Thread (Concepts in C++20; Coroutines, Ranges and Networking TSes published) : cpp". 15 July 2017.

References

[edit]
[edit]
脚拇指外翻是什么原因造成的 血小板吃什么补得快点 肾小球滤过率偏高说明什么 梦见小牛犊是什么预兆 盥洗室什么意思
让姨妈推迟吃什么药 1969年属什么 2 26是什么意思 2222是什么意思 人中起痘痘是什么原因
梦见被追杀预示什么 灰溜溜是什么意思 白骨精什么意思 皮肤容易晒黑是什么原因 蜂蜜和什么不能一起吃
葫芦代表什么生肖 肝脏不好吃什么调理 女人出虚汗是什么原因引起的 吃什么药马上硬起来 中线是什么意思
8月15是什么星座hcv9jop4ns4r.cn 免疫五项能查出什么病hcv9jop3ns6r.cn 大便有粘液是什么原因hcv8jop8ns1r.cn 泡脚什么时候最佳时间hcv9jop4ns5r.cn 一杆进洞叫什么球hcv9jop6ns6r.cn
奸诈是什么意思hcv8jop8ns5r.cn 什么是着相hcv8jop6ns1r.cn nub是什么意思hcv7jop4ns8r.cn 血管炎不能吃什么食物hcv7jop9ns4r.cn 外阴白斑瘙痒抹什么药hcv7jop7ns2r.cn
人流挂什么科cj623037.com 调兵遣将是什么生肖hcv8jop4ns4r.cn 宝宝头爱出汗是什么原因hcv7jop9ns1r.cn 噬血细胞综合征是什么病hcv9jop7ns5r.cn 吃钙片有什么好处hcv8jop8ns8r.cn
女人吃桑葚有什么好处gysmod.com 胃胀气打嗝是什么原因wmyky.com 独在异乡为异客异是什么意思hcv7jop5ns0r.cn 普外科是看什么病的hkuteam.com yy是什么hcv9jop1ns8r.cn
百度