In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how C++ defines concepts for template parameters". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "how C++ defines concepts for template parameters" together.
T.10: Define concepts for all template parameters
Reason
Correctness and readability. The assumed meaning (syntax and semantics) of a template argument is fundamental to the interface of a template. A concept dramatically improves documentation and error handling for the template. Specifying concepts for template arguments is a powerful design tool.
correctness and readability. The assumed meaning (syntax and semantics) of a template parameter is the basis of the template interface. The concept greatly improves template documentation and error handling. Defining concepts for template parameters is a powerful design tool.
Example
template
// requires Input_iterator
// && Equality_comparable
Iter find(Iter b, Iter e, Val v)
{
// ...
}
or equivalently and more succinctly:
Or use the following functionally equivalent, but simpler, approach:
template
// requires Equality_comparable
Iter find(Iter b, Iter e, Val v)
{
// ...
}Note
"Concepts" are defined in an ISO Technical Specification: concepts. A draft of a set of standard-library concepts can be found in another ISO TS: ranges Concepts are supported in GCC 6.1 and later. Consequently, we comment out uses of concepts in examples; that is, we use them as formalized comments only. If you use GCC 6.1 or later, you can uncomment them:
"Concept" is defined by ISO technical specifications: concepts. A preliminary version of a standard library concept can be found in another ISO specification: ranges. GCC 6.1 supports concepts. So we commented out concepts in our example code; that is, we used them as standard comments. If you are using a later version of GCC 6.1, you can open comments.
template
requires Input_iterator
&& Equality_comparable
Iter find(Iter b, Iter e, Val v)
{
// ...
}Note
Plain typename (or auto) is the least constraining concept. It should be used only rarely when nothing more than "it's a type" can be assumed. This is typically only needed when (as part of template metaprogramming code) we manipulate pure expression trees, postponing type checking.
A straightforward type name (or auto) is the concept of minimal constraint. It should be used sparingly and limited to expressing "it is a type." This is usually only necessary (as part of template metaprogramming) when we operate on pure expression trees, deferred type checking.
Thank you for reading, the above is "C++ how to define the concept of template parameters" content, after the study of this article, I believe we have a deeper understanding of how C++ defines the concept of template parameters, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.