官术网_书友最值得收藏!

  • Expert C++
  • Vardan Grigoryan Shunguang Wu
  • 135字
  • 2021-06-24 16:33:52

Concepts

Concepts are a major feature in C++20 that provides a set of requirements for types. The basic idea behind concepts is the compile-time validation of template arguments. For example, to specify that the template argument must have a default constructor, we use the default_constructible concept in the following way:

template <default_constructible T>
void make_T() { return T(); }

In the preceding code, we missed the typename keyword. Instead, we set a concept that describes the T parameter of the template function.

We can say that concepts are types that describe other types – meta-types, so to speak. They allow the compile-time validation of template parameters along with a function invocation based on type properties. We will discuss concepts in detail in Chapter 3Details of Object-Oriented Programming, and Chapter 4, Understanding and Designing Templates.

主站蜘蛛池模板: 昭通市| 胶州市| 罗平县| 嘉兴市| 中宁县| 攀枝花市| 察哈| 大同市| 云林县| 正安县| 甘肃省| 齐齐哈尔市| 镇安县| 林西县| 开封县| 宾川县| 慈利县| 藁城市| 汕头市| 宜兰市| 禄劝| 陵川县| 北碚区| 永昌县| 天台县| 寻乌县| 井研县| 布拖县| 蒲江县| 碌曲县| 子长县| 昆山市| 汉沽区| 临沧市| 广汉市| 庆元县| 平乡县| 西昌市| 泗洪县| 内丘县| 黄陵县|