"C + + Primer Plus", chapter 16th, String class and Standard Template Library learning notes

Source: Internet
Author: User

C + + provides a powerful set of libraries that provide solutions to many common programming problems and tools for simplifying other issues the string class provides a convenient way to handle strings as objects. The string class provides automatic memory management kinetic energy and many methods and functions for handling strings. For example, these methods and functions allow you to combine strings, insert a string into another string, invert strings, search for characters in a string, or sister Fuchuan, and perform input and output operations.
Smart pointer templates such as AUTO_PTR and c++11 new shared_ptr and unique_ptr make it easier to manage the memory allocated by new. If you use these smart pointers (rather than regular pointers) to save the address returned by new, then the delete operator is not used later. When a smart pointer object expires, its destructor automatically calls the delete operator.
STL is a collection of container class templates, iterator class templates, function object templates, and algorithmic function templates that are consistent in their design and are based on generic programming principles. The algorithm is independent of the type of the stored object by using the template, which is independent of the container type by using the iterator interface. Iterators are generalized pointers.
STL uses the term "concept" to describe a set of requirements. For example, the concept of a forward iterator includes the requirement that a forward iterator can
Enough to be dereferenced to read and write, and to be incremented when asked. The concept of real implementation is called the conceptual "model" for example, the forward iterator concept can be a regular pointer or a navigation list object. Concepts based on other concepts are known as "improvements" for example, bidirectional iterators are improvements to the concept of forward iterators.
Container classes such as vectors and set are models of container concepts such as containers, sequences, and associated containers. STL defines a variety of container class templates: Vector, deque, list, set, Multiset, map, Multimap, and Bitset; The adapter class template queue, Priority--queue, and stack are also defined, which allow the underlying container class to provide an attribute interface recommended by the adapter class template name. Therefore, although stack is vector-based by default, it is still only allowed to be inserted and deleted at the top of the stack. C++11 added Forward_list, unordered_set, UNORDERED_MULTISCT, Unordered_map, and Unordered_multimap.
Some algorithms are represented as container class methods, but a large number of algorithms are represented as generic, non-member functions, which are implemented by using iterators as interfaces between containers and algorithms. One advantage of this approach is that you need only one function, such as for_each () or copy (), without having to provide one version for each container, and another advantage: the STL algorithm can be used in non-STL containers such as regular arrays, string objects, The array object and any classes you design adhering to STL iterators and container rules.
Both containers and algorithms are characterized by the type of iterator they provide or require. You should check whether the container has an iterator concept that supports the algorithm requirements. For example, the For_each () algorithm uses an input iterator, and all STL container class types meet their minimum requirements: while sort () requires a random-access iterator, not all container classes support this iterator. If the container class does not meet the requirements of a particular algorithm, it may provide a dedicated method. For example, the list class contains a sort () method based on a bidirectional iterator, so it can use this method instead of a generic function.
The STL also provides function objects (function characters) that are overloaded with the () operator (that is, the class that defines the operator () () method). You can use function notation to invoke objects of this class, while carrying additional information. The adaptive function has a TypeDef statement that identifies the parameter type and return type of the function character. This information can be used by other components, such as function adapters.
By representing commonly used container types and providing a variety of common operations that are implemented using efficient algorithms (all implemented in a common way), STL provides a very good source of reuse code for grams. You can use STL tools directly to solve programming problems, or they can be seen as basic to build the solution you need.
The template classes complex and Valarray support numeric operations of complex numbers and arrays.

"C + + Primer Plus", chapter 16th, String class and Standard Template Library learning notes

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.