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

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.

主站蜘蛛池模板: 汕头市| 临江市| 堆龙德庆县| 临湘市| 铁岭县| 东阳市| 内乡县| 南汇区| 洛川县| 陆丰市| 和政县| 德庆县| 河津市| 青海省| 济阳县| 定南县| 调兵山市| 银川市| 安化县| 巫山县| 德清县| 罗定市| 云龙县| 广宁县| 霍林郭勒市| 盐城市| 旬阳县| 福清市| 迁安市| 金堂县| 乌拉特前旗| 区。| 额济纳旗| 泸水县| 泸西县| 巴楚县| 交城县| 濉溪县| 华亭县| 长海县| 金坛市|