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

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

主站蜘蛛池模板: 阳城县| 皋兰县| 湄潭县| 武山县| 临高县| 舟山市| 马公市| 邵阳市| 东兴市| 宁晋县| 桂林市| 东辽县| 鄢陵县| 抚远县| 老河口市| 宣化县| 五大连池市| 西充县| 河北省| 正蓝旗| 绩溪县| 沁阳市| 石阡县| 繁峙县| 东海县| 金溪县| 翁源县| 宕昌县| 景谷| 天祝| 玛纳斯县| 房山区| 商都县| 彝良县| 芦山县| 洪湖市| 兰西县| 桐梓县| 昌平区| 大冶市| 综艺|