Sender: huxw (Mi Duck and Tang Mouse), the letter area: Programming Title: Boost :: Concept_Check Send Station: BBS Shuimu Tsinghua Station (Mon May 13 14:21:45 2002)
Follow up, this is relatively simple;)
Boost concept check library
One: Why?
"Concept Check" means similar to Design by Contract, I think. A simple example,
1 #include 2 #include
This has an obvious mistake. List does not have a random access, and it is obviously not to meet the requirements of Stable_Sort. That is, this program is wrong. But can the compiler tell us? See what they are saying .
[VC6]: / Program Files / Microsoft VisualStudio / VC98 / include / algorithm (579): Error C2784: 'Classstd :: Reverse_Iterator <_ri, _ty, _rt, _pt, _d> __cdecl std :: operator (_ D, const class std :: REVERSE_ITERATOR <_ri, _ty, _rt, _pt, _d> &): COULDNOT DEDUCE TEMPLATE ARG Ument for '' from 'Class std :: list
For an initiator, the error message given by the compiler not only does not illustrate the reason, but also intentionally, the idea of people goes into the wrong direction. The author of Concept_Check summarizes this four points:
1. Because the compiler error caused by the wrong template parameter is similar. It is often erroneous from the caller of the template, but the compiler throws out the internal implementation of the template to see .2. Document as a document The CONCEPT may not completely match the template itself, so it may appear, the user is clearly called the template in the documentation, or there is an inexplicable error
3. Documentized Concept is too bound to exceed the template truly needs.
4. Concept is not expressed in the code, which makes the code difficult to understand; and the code and document are difficult to synchronize.
Compiled
[G 2.95.3] D: / mingw / bin /../2 / gcc-lib / mingw32 / 2.95.3-5 /../..../../ include / g - 3 / STL_ALGOH: In Function `Void __inplace_stable_sort <_list_iterator
For an initiator, the error message given by the compiler not only does not illustrate the reason, but also intentionally, the idea of people goes into the wrong direction. The author of Concept_Check summarizes this four points:
1. Because the compiler error caused by the wrong template parameters is similar. It is often erroneous in the template caller, but the compiler throws out the internal implementation of the template to see the programmer.
2. The Concept recorded as a document may not be completely consistent with the template itself, so it is possible that the user calls the template in the instructions of the document, or there is an inexplicable error.
3. Documentized Concept is too bound to exceed the template truly needs.
4. Concept is not expressed in the code, which makes the code difficult to understand; and the code and document are difficult to synchronize.
Concept_Check can provide:
1. Insert the compile period template parameter check
2. Create a framework that expresses the Concept request by the Concept Checking class (Framework)
3. Mechanism that can verify template parameters
II. How to use
Concept is very simple, two things [function_requires] is used inside the template function. such as Template
In a just example, if we have modified the Stable_Sort code in Algorithm, then ...
The result of the output should be sauce purple:
D: / mingw / bin / mingw32 / 2.95.3-5 /../..../../ incrude / boost / concept_check.hpp: in Method `Void boost: : ComparableConcept <_list_iterator
3. Implementation
The CONCEPT class implementation is simple, there must be a non-static member function for void constraints (), which is used back to function_requires. And, it is best to add a concess suffix to your class name, which can explain This class is dry.
Other
It is best to look at the concept_check.hpp file, the code is not complicated, boost_class_requires appear here to the keywords such as RandomaccessIitorConcept, QQ.cpp: 6. And the word "of Concept_Check is also reminding the programmer, the cause of the error is in yourself Not the library. The error message is still very long, although it is a little bit more than the original. (3. Implemented in the expansion
The CONCEPT class implementation is simple, there must be a non-static member function for void constraints (), which is used back to function_requires. And, it is best to add a concess suffix to your class name, which can explain This class is dry.
Other
It is best to look at the concept_check.hpp file, the code is not complicated, boost_class_requires is a macro for assembling the function.
- AbcdefghijklmnopqrStuvwxyzabcdefghijklmnopqrStuvwxyz
※ Source: · BBS Shuimu Tsinghua Station bbs.edu.cn · [from: 166.111.64.166]