Nothing to talk about C ++ LAN chat software

Source: Internet
Author: User

In general, when we chat on a LAN, we basically merge the data in a model based on the object attributes. In fact, when we design the model of this object, have we considered model granularity refinement? Although model granularity refinement increases the cost of dimensions, it also increases the flexibility of the system. The first condition is that the granularity of the model should be rationalized. (This article only about the design does not talk about the attribute of the model attribute field) LAN chat software download: http://www.freeeim.com/

C. max_size ()
Returns the maximum number of elements possible

C1.swap (C2)/swap (C1, C2)
Swaps the data of c1and C2

C. Begin ()/C. End ()
Returns an iterator for the first element/the position after the last element

C. rbegin ()
Returns a reverse iterator for the first element of a reverse Iteration

C. rend ()
Returns a reverse iterator for the position after the last element of a reverse Iteration

C. insert (Pos, ELEM)
Inserts a copy of ELEM (return value and the meaning of POS differ)

C. Erase (beg, end)
Removes all elements of the range [beg, end) (some containers return next element not removed)

C. Clar ()
Removes all elements (makes the container empty)

2. (p149)
Vector size and capacity)

Size indicates the number of elements in the current container.

Capacity indicates the number of elements that a vector can hold. If this value is exceeded, the internal memory is reconfigured.

Use resize (Num) or resize (Num, ELEM) to change the number of elements to num.

Use reserve (Num) to change the number of vectors to num.

Capacity> = size

The vector container cannot assign values to a non-existent space. That is to say, the assign () value of the vector can be [begin (), end ). Note that this is the range of size, not the range of capacity.

3. (p158)
Class vector <bool>

It seems that this is not very useful, but it is definitely not good.

Effective C ++: Avoid using vector <bool>

I also found a discussion post on the Internet:

Http://topic.csdn.net/t/20040511/15/3054586.html

4. (p163)
Deque

Most deque and vector are similar. The following are some differences:

1. deque does not provide capacity operations (capacity () and reserve ()).

2. deque directly inserts and deletes header elements (push_front () and pop_front ())

Deque also has a feature. The insertion or deletion of elements may lead to memory reallocation. Therefore, any insertion or deletion will invalidate all pointers, references, and iterator pointing to the deque element. The only exception is to insert an element in the header or tail.

5. (p169)
List

The Special versions of remove () and remove_if () are added in list as their member functions. Therefore, in the face of list, we should call the member function remove () instead of the STL Algorithm for calling like vector <> or deque <>.

Special modifying operations)

For the splice function, pay attention to how to transfer through the linked list, for example:

After the c1.splice (Pos, C2) operation, the original C2 is empty.

Take the following example and pay attention to the result.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Author: tanky Woo
// Blog: www.wutianqi.com
# Include <cstddef>
# Include <iostream>
# Include <vector>
# Include <list>
# Include <deque>
# Include <set>
# Include <algorithm>
# Include <iterator>
Using namespace STD;

Void printlists (const list <int> & L1, const list <int> & l2)
{
Cout <"list1 :";
Copy (l1.begin (), l1.end (), ostream_iterator <int> (cout ,""));
Cout <Endl <"list2 :";
Copy (l2.begin (), l2.end (), ostream_iterator <int> (cout ,""));
Cout <Endl;
}

Int main ()
{
// Create two empty lists
List <int> list1, list2;

// Fill both lists with elements
For (INT I = 0; I <6; ++ I ){
List1.push _ back (I );
List2.push _ Front (I );
}
Printlists (list1, list2 );

// Insert all elements of list1 before the first element with value 3 of list2
//-Find () returns an iterator to the first element with value 3
List2.splice (find (list2.begin (), list2.end (), // destination position
3 ),
List1); // source list
Printlists (list1, list2 );

// Move first element to the end
List2.splice (list2.end (), // destination position
List2, // source list
List2.begin (); // Source Position
Printlists (list1, list2 );

// Sort second list, assign to list1 and remove duplicates
List2.sort ();
List1 = list2;
List2.unique ();
Printlists (list1, list2 );

// Merge both sorted lists into the first list
List1.merge (list2 );
Printlists (list1, list2 );
System ("pause ");
Return exit_success;

}

Result:

List1: 0 1 2 3 4 5
List2: 5 4 3 2 1 0

List1:
List2: 5 4 0 1 2 3 4 5 3 2 1 0

List1:
List2: 4 0 1 2 3 4 5 3 2 1 0 5

List1: 0 0 1 1 2 2 3 3 4 5 5
List2: 0 1 2 3 4 5

List1: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 5 5 5
List2:

6. (p180)
Set/Multiset special search functions

Just as list provides special versions of remove () and remove_if (), set/Multiset also provides special search functions, they can execute jobs faster than STL functions with the same name.

Count (ELEM)
Returns the number of elements with value ELEM

Find (ELEM)
Returns the position of the first element with value ELEM or end ()

Lower_bound (ELEM)
Returns the first position, where ELEM wocould get inserted (the first element> = ELEM)

Upper_bound (ELEM)
Returns the last position, where ELEM wocould get inserted (the first element> ELEM)

Performance_range (ELEM)
Returns the first and last position, where ELEM wocould get inserted (the range of elements = ELEM)

7. (p181)
For assign or swap of set/Multiset, if the criterion is different, the criterion itself will also be assigned or exchanged.

8. (p183)
Set/Multiset does not provide the remove () operation. However, C. Erase (ELEM) can be used to delete the "equal to ELEM" element.

The insert function of set/Multiset can insert only one element at a time.

The Return Value of the insert function of set is a pair type. First indicates the position of the new element or the position of the same element already contained. Second indicates whether the insert operation is successful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
STD: pair <STD: Set <float >:: iterator, bool> status;

// Insert value and assign Return Value
Status = C. insert (value );

// Process return value
If (status. Second ){
STD: cout <value <"inserted as element"
}
Else {
STD: cout <value <"already exists as element"
}
STD: cout <STD: distance (C. Begin (). Status. First) + 1
<STD: Endl;

9. (198)
Set/Multiset can be considered as a special map/multimap, but the value and key of the Set element point to the same object. Therefore, MAP/multimap has all set/Multiset capabilities and all operation functions.

Similar to set/multimap, MAP/multimap provides special search functions. Note that the parameter of the member function find () Here is the key. That is to say, you cannot use find () to search for elements with a specific value, but you can use find_if (). Count (key), find (key), lower_bound (key), upper_bound (key), 1__range (key) and other parameters are keys.

In MAP/multimap, the keys of all elements are regarded as constants. Therefore, the actual element type is pair <const key, T>. This restriction is used to ensure that you do not change the order of sorted elements because of changing the key of the elements.

You must be familiar with the subscript operations of map, and the subscript operations get the value directly.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.