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

  • 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.

主站蜘蛛池模板: 中阳县| 阳城县| 望谟县| 永川市| 桐城市| 福州市| 南靖县| 三河市| 贵南县| 青海省| 镇宁| 斗六市| 体育| 怀安县| 阿鲁科尔沁旗| 岳阳县| 延边| 宜川县| 儋州市| 江山市| 若羌县| 滦南县| 白河县| 卫辉市| 交口县| 澄迈县| 中阳县| 宜阳县| 五常市| 富民县| 延寿县| 肥西县| 柞水县| 江西省| 彭水| 东源县| 巴里| 手机| 清水县| 高要市| 罗平县|