Boost journey (1)

Source: Internet
Author: User

========================================================== ==============================================
I have been using boost for many years, but I have never been able to study it in depth due to my laziness. Today, when we opened beyond the C ++ standard library: An Introduction to boost again, we found that boost still shines in a strange light and guides me. I know that this time we should follow this path and enter the more magnificent and magnificent field of C ++, where there is the most beautiful part of human reason.
========================================================== ==============================================
Boost (First Day)
[Before line]
Boost is a C ++ library. Due to its excellent production, it is likely to become another c ++ standard library after STL. Of course, for C ++ programmers, the boost library is too large. When you log on to www.boost.org for the first time, you will not be lost in the URL page of the ditch. In addition, boost is an Open Library that comes from experts in different fields of C ++. The Code style varies, and the documentation is simplified. Therefore, for a newbie, boost is "full Chinese banquet". Not only do you have to have food experience to walk in different cuisines, but you also have a strong appetite for overload, in order to get a taste of it.
For a generation of programmers who have grown up in Windows, the Boost library is even more "singular"-there is no uniform style document/no help from Ctrl + F1, there is not even a Windows Standard "Next" installation program. It is no wonder that when they open the Boost library in Visual Studio/C ++ Builder, they will "wow" be magnificent, "Ah" be unavailable. The use of Boost debugging seems a bit "Nightmare" for Windows programmers! But you need to know that many of these Boost builders are older than Windows, and many have never worked on Windows platforms. For them, Windows is a commercial product, not the whole of computer software.
Based on this, I hope that my Boost journey will take C ++ programmers on the Windows platform to look at the waves, play with water, or take a trip to the ocean.
========================================================== ========================================, Look at several small islands in the sea
"C ++ is a pioneering language", which has been circulating since the 1980s S. But today's new-generation programmers look back at C ++ after reading Java/C # and other languages. "The old language without the string type"/"the one without garbage collection (GC "......, When they face character processing problems that can be easily solved in Java/C # In C ++, they are overwhelmed with complaints. Oh, I caught it first. Otherwise, I won't be able to accept the deadline when I was thirty years old. In C ++, you can easily process characters. This is not a fantasy. Although the C ++ language does not involve many technical details about character processing, there are good function libraries available in STL and Boost, its convenience and speed are not inferior to Java/C #. So let's take a look at the character processing in Boost.
Boost. Regex is a library in Boost that solves regular expressions. A Regular Expression is a set of character string that can be used to filter, search, locate, and perform other complex operations on strings. Regular expressions were widely used in Perl at the earliest-as a tool for text processing, they made great contributions in the infancy of WWW. Later, in many languages, Regular expressions became part of the language as a standard library. For example, Microsoft's C # language contains a powerful Regular library (which is.. Net Framework library ). Boost. Regex gives C ++ programmers the ability to control regular expressions, so that they can easily deal with various complex text processing problems. Boost. Regex will be a library we will learn in detail.
If Boost. Regex is the dagger of Text Processing for common C ++ programmers, Boost. Spirit is the sword of computing science experts. It mainly solves how to implement the language analysis function, that is, the command line-level text analyzer. With the help of Spirit, writing a program Pre-compiler should not be "difficult. But in the face of it, we only browsed it once, because for Boost beginners, the knowledge of computing science involved by Spirit is too deep.
Boost. String_algo is a set of string-related processing functions, including conversion, reduction, and cutting operations. It is the most common string processing library.
Boost. Tokenizer is used to cut a string of characters into multiple tokens, which plays an important role in serial transmission and control.
In view of the above analysis, we will look up at the Spirit peak among the many peaks on the Character Processing Island, climb the Regex/String_algo peak, and visit Tokenizer peak at will.
========================================================== ==============================================
Data structure is a basic course for each computer discipline. Currently, the teaching language of this course in China is generally C ++. Unfortunately, the C ++ program taught in data structure is often not a C ++ program in the modern sense, many of them use the C language (or even the old C language ). If you don't talk about the language, the programming concepts in the teaching program are also old, and young people who love the newest are often not interested in this course. In fact, in C ++, data structure knowledge can help us develop faster, better, and better programs. Learning the data structure is extremely important for the development of programmers. Well, let's talk about it all the time. Let's look at the data structures inspired by another small island in boost.
Boost. Any is a library used to access any type of information. It is safe and efficient, and can be used all over the world. For "lazy" programmers, The any database can create a storage space with security insurance to ensure that the storage space is not lost when it is put into any type.
As the name implies, the boost. array library is a powerful array library. Take strong and safe care of arrays under C. This gives us an alternative to STD: vector.
The boost. compressed_pair library reinforces STD: pair to save storage space. Pair is two associated variables that can be operated simultaneously. This helps solve many engineering problems, for example, a function returns two values.
Boost. dynamic_bitset is an extension of STD: bitset.
Boost. graph is an important function library for Boost data types. It contains many generic functions in graph theory, such as dijsktra shortest path algorithm. This library can be used to deal with problems related to graph theory. In view of its importance, we will take a closer look at the use of boost. Graph (remember to have a book dedicated to boost. graph ).
Remember, the most attractive concept when learning STL is iteration subator ). Beginners should be deeply touched by its magic in loop traversal. Now, the boost. iterator Library Extends the iterator of the original STL so that it can be applied to new iteration types, and supports many powerful operations. Wow! Perhaps we should refer to Hou Jie's ideas to start the boost Data Structure journey here!
Multi-dimensional arrays have been a pain point for C ++ programmers for many years. In many dynamic languages, why can we wave multidimensional arrays flexibly, while in C ++, We need to manually convert them to a single dimension and carefully prevent latitude overflow errors? Now Boost. MultiArray frees you. In the near future, Multi-dimensional indexes can be created using the Boost. Multi-index library. "Can I DIY a micro-database? ", With the help of Boost, this does not seem to be a dream anymore.
If you are a Python programmer, you should be familiar with the range concept. Now Boost. Range introduces it to C ++.
Boost. Tuple, the genie in the data structure. Isn't it? Under the Boost. Tuple magic wand, everything that cannot be combined has been done together. The official explanation of Tuple is A fixed-length combination of values of a specific type (A tuple is a fixed-size collection of values of specified types .) A big vernacular is to combine a pile of data, but it is neither a Struct nor a Class or enumeration ). I'm looking forward to dancing with this genie, isn't it?
For those who have compiled OLE (ActiveX) in Windows, Variant cannot go around. Variant has its charm and can store multiple types of values at will. It also has its stubborn weakness. If it is not used well, it will not be known about its true nature. However, the use of Variant in Windows is becoming increasingly popular. The Boost. Variant library is used to deal with the Variant problem in C ++.
I think if a student studying "Data Structure", after learning the basic data structure theory with STL, will focus on Boost, it will be able to improve a lot of ability.
========================================================== ==============================================
In C/C ++, function concepts are at the core. We cannot talk about the C/C ++ language without functions. But does the function mean the same as structured programming thought 30 or 40 years ago? The answer is no. Functions in modern programming theory have been extended. In the simple appearance of the function, the concept of being young exists. When you walk in the Boost library, you will surely hear it solid and cheerful.
Boost. Bind, a magical great work. It can bind the function Ontology with the function input value. You may be surprised that the input of a function is called together with the function body? Let's take a look at the Demo code below to see if you can feel the magic of Bind (here the code is the strongest)

 

# Include <iostream>
# Include "Boost/Bind. HPP"

Void nine_arguments (
Int i1, int i2, int i3, int i4,
Int i5, int i6, int i7, int i8, int i9 ){
Std: cout <i1 <i2 <i3 <i4 <i5
<I6 <i7 <i8 <i9 <'\ n ';
}

Int main (){
Int i1 = 1, i2 = 2, i3 = 3, i4 = 4, i5 = 5, i6 = 6, i7 = 7, i8 = 8, i9 = 9;
(Boost: bind (& nine_arguments, _ 9, _ 2, _ 1, _ 6, _ 3, _ 8, _ 4, _ 5, _ 7 ))
(I1, i2, i3, i4, i5, i6, i7, i8, i9 );
}

Boost. Function can implement generalized callback functions, while Boost. Functional enhances the Adapter in STL. Lambda functions are the most commonly used tool for Python users. lambda also provides C ++ users to create such functions only when called (to avoid abuse of small objects) and is very suitable for function calls of STL algorithms. In contrast, Boost. Ref is used to reference and encapsulate objects so that other object functions can be called. Boost. Signals is used to create a message-driven program.
========================================================== ==============================================

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.