Standard Template Library Introduction (2)

zhaozj2021-02-16  43

Refinement

Input Iterator is, in fact, a rather weak concept:. That is, it imposes very few requirements An Input Iterator must support a subset of pointer arithmetic (it must be possible to increment an Input Iterator using prefix and postfix operator ), but need . not support all operations of pointer arithmetic This is sufficient for find, but some other algorithms require that their arguments satisfy additional requirements Reverse, for example, must be able to decrement its arguments as well as increment them; it uses the expression -. Last. in Terms of Concepts, We say the Reverse's Arguments Must Be Models of Bidirectional Iterator Rather Than Input Iterator.

Improve

Input_iterator is actually a fairly weak concept: that is, it only puts a quite requirement. An input_iterator must support a subset of the acupuer operation (you must use the prefix and suffix operator to add an input_iterator), but There is no need to support all the operations of pointer operations. This is enough for Find, but other algorithms also require their parameters to meet some additional requirements. For example, Reverse must be able to increase and reduce operations to its parameters, which uses expressions --last. From the concept, we say that Reverse 's parameters must be the model of the Bidirectional_iterator instead of the input_iterator.

The Bidirectional Iterator concept is very similar to the Input Iterator concept: it simply imposes some additional requirements The types that are models of Bidirectional Iterator are a subset of the types that are models of Input Iterator:. Every type that is a model of Bidirectional Iterator is also a model of Input Iterator Int *, for example, is both a model of Bidirectional Iterator and a model of Input Iterator, but istream_iterator, is only a model of Input Iterator:. it does not conform to the more stringent Bidirectional Iterator requirements .

Bidirectional_Iterator concept is very similar to the Input_iterator: it is just an additional request. The type of the model for the Bidirectional_iterator is a subset of the type of the model of the input_iterator: Each is a model of the model of the bidirectional_iterator. For a model of the input_iterator. For example, int * both Bidirectional_Iterator model is Input_Iterator model, but istream_iterator just a model Input_Iterator: it does not meet the more stringent requirements of Bidirectional_Iterator .We describe the relationship between Input Iterator and Bidirectional Iterator by saying that Bidirectional Iterator is a refinement of Input . iterator refinement of concepts is very much like inheritance of C classes; the main reason we use a different word, instead of just calling it "inheritance", is to emphasize that refinement applies to concepts rather than to actual types.

By saying that bidirectional_iterator is a refining of Input_iterator, we describe the relationship between input_iterator and bidirectional_iterator. The concept's refining is very similar to the inheritance of the C class; we use a different word instead, it is the reason for the inheritance is to emphasize refining. Applying to concept rather than actual types.

There are actually three more iterator concepts in addition to the two that we have already discussed: the five iterator concepts are Output Iterator, Input Iterator, Forward Iterator, Bidirectional Iterator, and Random Access Iterator; Forward Iterator is a refinement of Input Iterator, Bidirectional iterator is a refinement of Forward iterator, and Random Access iterator is a refinement of Bidirectional iterator (Output iterator is related to the other four concepts, but it is not part of the hierarchy of refinement:. it is not a refinement of any of the Other Iterator Concepts, And None of the Other Ite.......................... ..

In addition to the two iterator concepts we have discussed, there are still three iterator concepts: These five iterator concepts are: output_iterator, input_iterator, forward_iterator, bidirectional_iterator and random_acess_iterator; forward_iterator is Input_Iteerator A refining, bidirectional_iterator is a refining of forward_iterator, and random_acess_iterator is a refining of Bidirectional_iterator (Output_iterator is associated with other four concepts, but it is not part of the refining system: it is not a refining of any other iterator concept, and other iterator concept Nor is it a refining). More information about iterators in an iterator. Connets, are Organized Into a hierarchy of concepts. All Containers Are Models of the Concept Container; More Refined Concepts, Such As Sequence and Associative Container, Describe Specific Types of Containers.

Containers, like an iterator, is organized as a conceptual system. All containers are model of Container concept, more accurate concepts, such as Sequence and Associative Container, describe the specific type of container.

Other Parts of The STL

If you understand algorithms, itemstors, and contact, then you understand almost everything there.................... ..

STL's other part

If you understand the algorithm, iterators, and containers, you almost understand almost everything about STL. However, STL does also contain several other types of components.

First, the STL includes several utilities: very basic concepts and functions that are used in many different parts of the library The concept Assignable, for example, describes types that have assignment operators and copy constructors; almost all STL classes are models of Assignable,. And Almost All Stl Algorithms Require Their Arguments to Be Models of Assignable.

First, STL includes several Utilities (tools): Very basic concepts and functions for many different parts of the library. For example, the concept assignable describes the type with assignment operators and copy constructors, almost all STL classes Both are the model of Assignable, and almost all STL algorithms require their parameters to be ASSIGNABLE models.

Second, The Stl Includes Some Low-Level Mechanisms for Allocating and Deallocating Memory. Allocators Are Very Specialized, and You CAN Safely Ignore The for Almost All Purposes.

Second, STL includes some underlying mechanisms for allocating and recovering memory. AlsoCators can ignore them. Finally, The STL includes a large collection of function Objects, Also Known As Functors. Just as iterators are a generalization of pointers, function objects are a generalization of functions: a function object is anything that you can call using the ordinary function call syntax There are several different concepts relating to function objects, including Unary function (a function object that. Takes a Single Argument, IE One That Is Called AS F (X)) And Binary Function (A Function Object That Takes Two Arguments, IE One That IS Called AS F (X, Y)). Function Objects Are An Important Part of Generic Programming Because The Allow Abstract Not Only over The Types of Objects, But Also over The Operations That Are Being Performed.

Finally, STL contains many function objects, also called FunCTOR, just like Iterator is the generalization of the pointer, Function Objects is the generalization of functions: a Function Object is anything you can call syntax calls with usual functions. Different concepts associated with Function Objects, including Unary Function, for, for example, F (x)), and binary function, for, for example, FUNCTION Object, such as function Objects. It is an important part of generic programming because they allow not only abstraction of the type of object, but also abstracted the operation performed.

转载请注明原文地址:https://www.9cbs.com/read-24831.html

New Post(0)