Experience STL. NET[Translation] zengyi820 2004-10-07
To better adapt STL.. NET development, Visual C ++ product group, re-designed STL in Visual C ++ 2005 and named it STL. NET, which is provided from Beta1 products.In STL. NET Design,
"Effective STL" in a sentence of advice, as far as possible to replace the handwritten loop algorithm, search for the loop traversal, where summarized commonly used STL lookup algorithm;
There are three kinds of search, that is, Dot line:The point is to find the target as a single element;Line is to find the target for the interval;The face is to find the target
1th: Carefully select the type of container.
Standard STL sequence Containers: Vector, String, deque, and list.
Standard STL Associative containers: Set, Multiset, map, and Multimap.
Non-standard sequence containers slist and rope. Slist is a one-way list, rope is essentially a "heavy" string.
Non-standard associative containers hash_set, Hase_multiset, Hash_map and Hash_multimap.
Vector as a substitute fo
the employee's office compartment number. The employee information is stored in the database, but the employee compartment number is irrelevant for most applications, so the database does not optimize for checking them. To prevent your program from burdening the database, you can write a function findcubiclenumber to cache the data you find. You can find it in the cache when you need the partition number that has been acquired, instead of querying the database. (reading data into memory)Here's
. Bitset class operator and member functionsBitset provides a number of useful operators, such as:>> inserts a character into the Bitset object; execution of bitwise and;| Perform a bitwise OR;^ Perform bitwise XOR;~ Perform bitwise inversion;>>= performs a bitwise right SHIFT operation;shift operation;operator [N] Provides reference access to similar array subscripts;A bit is one or all of the bits in a bitset that can be stored in two states, bitset content operations, using the following memb
operation.ExampleWatermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /southeast ">#include The result of the execution is:Second, unique_copy functionThe algorithm standard library defines a function named Unique_copy, which operates like a unique.The only difference is that the former accepts the third iterator, which specifies that the target sequence for copying elements is not repeated. Unique_copy literally means to remove repeated
:
Second, unique_copy function
The algorithm standard library defines a function called Unique_copy, which operates like a unique one.
The only difference is that the former accepts the third iterator argument, which specifies the target sequence for copying the distinct elements.
Unique_copy literally means to remove the repeating element and then perform the copy operation.
The writer uses unique_copy to assign a distinct element in a list object to an empty vector object.
1//using the uniqu
);
For example: 10 students in the class, calculating all students who have not passed (below 60 points):
Student Exam ("pass", 60);
Stable_partition (Vect.begin (), Vect.end (), bind2nd (less
7. Efficiency from high to low (time-consuming from small to large):
Partion
Stable_partition
Nth_element
Partial_sort
Sort
Stable_sort
8. The effective STL summarizes how to select the Sort function:
8.1
constructor in the auto_ptr source code are normal reference arguments (not const references, not normal values), which is to facilitate the transfer of pointer ownership (if it is a const reference, then ownership cannot be transferred; if it is a normal value, oh my God , the whole world is completely chaotic). If the copy is constructed with a temporary object (that is, the so-called rvalue), then it cannot be compiled (a normal pointer or reference cannot point to a const object, i.e. it ca
-we might call it standard C + + 1.1. If you're not familiar with TR1 functionality, you can't be called a effective C + + programmer, because the functionality in TR1 is a benefit for all kinds of libraries and applications.2. What is in the C++98 standard library?Before examining what is TR1, it is valuable to review the main parts of the c++98 version of the standard library:
Standard Template Library (
Effective C + + Chapter 1. Make yourself accustomed to C + + (Accustoming yourself to C + +) Item 1. View C + + as a language federation (View C + + as a federation of Languages) Consider C + + as a federation of four sub-languages, where codes and practices tend to be simple, straightforward, and easy to remember in a given sub-language. But moving from one sub-language to another, the code may change.
C --c++ is based on C. Chunks (blocks
Nlcomponent object ... The linked list of the private: listDiagram between classesThe list class used in newsletter is a standard template class (STL), and STL is part of the standard C + + class library (see effective C + + clause 49 and clause M35). The behavior characteristics of a list type object are somewhat like a doubly linke
13 *//* Test the Special Swap Swap () in the effective STL */cout cout Vectorcout cout cout cout return 0;}Vi. other member functions of the vectorC.assign (Beg,end)Assigns the data in the [beg; end] Interval to C.C.assign (N,elem)Assigns a copy of n elem to C.c.at (IDX)Returns the index IDX refers to the data, if the IDX is out of bounds, throws Out_of_range.C.back ()Returns the last data without checking
need. After adding all the data, trim the redundant content.
Article 15: Be careful with the diversity of string implementations
Different implementations of string may cause some differences in the string feature, such as sizeof (string.
The creation of new string values may require 0, 1, or 2 dynamic allocation.
The string object may or may not share the size and capacity of the string.
String may be or may not support each object configurator.
Different implementations have different polici
of iterators can do each, at the same time can read or write its meaning more than once;4 bidirectional iterator is more powerful than the previous classification: it can move forward, but also move back, that is, bidirectional movement;5 Random Access Iterator is more powerful, not only can move in both directions, but also can move random step, that is, it can be in constant time forward or backward jump any distance.These five types of relationships can be expressed as:
struct input_iterator
Introduction: This article describes the methods of exporting STL classes and classes containing STL in DLLs. Example source code
DLLs cannot directly export generic templates (generalized template), so if you are exporting an STL class, the template must be instantiated (instantiated) first. In addition, if the exported STL
container, you should think of a value assignment. If you just copy a container to another container of the same type, operator = is the selection assignment function, but for the example demonstrated, when you want to give a container a completely new data set, assign can be used, but operator = cannot.
The second purpose of this test is to demonstrate why interval member functions take precedence over their single-element member functions. OneInterval member functionsIt is a member function
Before watching "C + + Primier", also solved in the sequential window Insert/erase will be involved in the problem of iterator failure, and did not delve into. I ran into this problem when I wrote the program today.
1 The inexplicable erase
Originally my program is purple, don't talk, I know this is a problem, but this is the most intuitive idea
Vector
Yes, the program crashes. After the iterator it was removed, the IT iterator was invalidated and no more ++it operations were possible.
Howe
It took me one night to translate an article about STL.Article. The first time I translated this kind of things, I felt that computer books are still better at the original English version, because many concepts cannot be properly expressed in Chinese (it's just that they can't be said ,:-)). Thanks to the first translation, the level must be relatively good. The key is that STL has never been seen before and is unfamiliar, so it is very hard to trans
It is estimated that this article will be written again by some "Bricks", but today I suddenly want to reflect on the STL source code analyzed during this period of time, so I have this article. this is my personal opinion, and we hope that the "brick-and-mortar" people will show their mercy.
What is STL (here )?
STL = standard template library, a standard templa
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.