Boost Common components Overview

Source: Internet
Author: User
Tags assert garbage collection mathematical constants portable file system square root time and date uuid
Preface

After a general review of which Luo Jianfeng's "Boost Library full Development Guide" (third edition), a summary of some of the commonly used boost library components described in the book is based on the introduction of the book, some of which also add their own description. The main purpose of this blog post is: (1) to carry out reading notes, easy to browse in the future, (2) share with you, also equivalent to doing a knowledge extraction, the use of some common components to summarize the purposes of the purpose to enable you to quickly understand the use of these commonly used components, in the future if there is need to use the place, you can learn and apply in-depth.

In short, this blog is not the online professional boost library source analysis, nor is the entire boost library professional analysis, just as a boost library in C + + application of reading notes to share with you, to help you understand some commonly used components, to avoid duplication of the build wheel. there is a good saying in the book: in the process of development, we must "avoid the repetition of the wheel" (this will only waste time, that is, thankless), so, if the development encountered in what problems, first look at the STL, Boost library, if you can not solve, and then the Internet, There is no reference to the existing plan to do their own.


Boost Common Libraries Overview 1, Time and date
C + + has always lacked the ability to handle time and date, and time and date are often encountered in real life, so C + + programmers have to resort to C, using clumsy structures and functions. Programmers who can't stand this situation have built their own first to meet the development needs, which has led many programmers to provide timer, Data_time, Chrono Three libraries to solve the problem, and avoid programmers repeating the wheel.

(1) The Timer library provides a simple measure of time and progress display, can be used for performance testing and other tasks need to be timed, for most of the situation he is sufficient.
(2) Data_time Library provides a comprehensive and flexible date-time library to simplify complex date and time processing work.
(3) The Chrono Library provides the "Computer World" time processing service to realize the precise timing of the computer system.


2. Memory Management
The C + + standard does not have garbage collection mechanisms such as Java, C #, and so on, which requires C + + programmers to avoid memory leaks, hanging pointers, and cross-border access. Boost offers a number of libraries to ensure efficient and correct memory management in C + +, including: Smart_ptr, Scoped_ptr, Scoped_array, shared_ptr, shared_ptr, Shared_array, Weak_ PTR, intrusive_ptr, pool, Object_pool, Singleton_ptr, Pool_alloc


3. Practical Tools Library
This is not a whole library, but a few of the smaller, simpler libraries in boost are grouped into a "tool library", which is not all classes, and there are macros, listed as:
(1) noncopyable component: A class that implements a prohibited copy;
(2) Ignore_unused components: Ensure that the program does not use but must retain the variables by compiling (without warning, note, do not ignore the compiler in the process of compiling the warning, to do 0 warning 0 error);

(3) Optional components: Packaging "may produce invalid value" objects, to ensure that these objects return a valid value or default value;

(4) Assign component: Provide simple, convenient standard library container assignment or initialization service, avoid repeatedly invoking insert, push_back method for assigning value or initializing a container;
(5) Swap component: the optimized swap function;
(6) Singleton component: Single case mode, the class that implements this pattern can only have and only one instance in the program life cycle;
(7) Tribool component: Tri-state bool type, including True, false, indeterminate (unknown, uncertain) three states;
(8) Operators components: running users in their own class only a small number of operators to define, you can easily automatically generate other operator overloading, and ensure the correct semantic implementation, such as a class only need to define = = and < operators, you can automatically generate!=, >, <=, >= these four kinds of operators;
(9) Exception component: Boost defined Exception class, is to the C + + standard Std::exception exception class improvement and enhancement;

(a) UUID component: representing and generating UUID (Universal unique identifier)

Config component: Boost Developer (not library user, we) tools, so don't worry;

(a) Utility library: This is not a unified theme of the boost library, contains a number of small but useful component tools;



4, string and text processing
Includes lexical_cast, format, String_ref, String_algo, Tokenizer, and Xpressive6 libraries, where:

(1) Lexical_cast and format are mainly concerned with the representation of strings, which can be converted to strings and accurately formatted for output.
(2) String_ref provides a read-only view that avoids the cost of copying strings, and is a better alternative to const std::string&.
(3) String_algo, Tokenizer and xpressive Three libraries are focused on string processing and provide a large number of string-handling functions.

5. Correctness and testing

This class of libraries is primarily designed to enhance bug detection in C + + programs, mainly including Assert, Static_assert, Lightweight_test, and test4 libraries.
(1) Assert library: Provides run-time assertions, and reinforces the assert in the C + + standard;
(2) Static_assert Library: Provide compile-time diagnosis;
(3) Lightweight_test and test library: providing unit testing functionality

6. Container and data structure
The Boost container library is an extension of the C + + standard container library, consisting mainly of 10 containers (data Structures): Array, Dynamic_bitset, unordered, Bimap, circular_buffer, tuple, any, variant, Multi_array, Property_tree.
(1) Array Library: The encapsulation of an array in C + + is part of the C++11 standard
(2) Dynamic_bitset Library: Combining the vector<bool> and bitset a bit, both dynamic growth, and facilitate the bit operation;
(3) Unordered Library: Hash container class (readers can own Baidu)
(4) Bimap Library: Similar to the C + + Standard Library association container, but the standard association container is only one-way association (mapping), and Bimap provides bidirectional mapping ability;
(5) Circular_buffer Library: Fixed size of the cyclic buffer;
(6) Tuple library: Yuan Zu, compared with the C + + standard library pair type, tuple can accommodate a number of elements, and each element can be different types;
(7) Any library: a container that can hold only one element, that is, the size of the container is fixed to 1, but the type of the element can be arbitrary;
(8) Variant Library: The extension and enhancement of the Union data structure in C + +, the union can only accommodate the built-in type of data, and the variant does not have this limitation;
(9) Multi_array Library: Multidimensional Array (container), similar to vector<vector<int> >;
(a) Property_tree library: A tree-shaped data structure that holds multiple attribute values;

7, algorithm
C + + standard library (STL) provides a large number of algorithms, you can perform statistics on the container, find, assign value, sort, and other operations, while boost also follow the standard library, provides some other algorithms to achieve, here mainly introduces three algorithm components: foreach, Minmax, algorithm.
(1) foreach component: The compiler level implementation of the Loop program structure (for example, for Loop), independent of the high-level compiler, which can also compile and run on the lower level compiler;
(2) Minmax components: Maximum value, minimum value application;
(3) Algorithm component: is an algorithm set, contains a lot of useful, small algorithm.

8. Mathematics and Numbers
C + + standard library The existing components for scientific computing are still unable to meet the modern scientific calculation requirements, boost library on this side of the Library to supplement, mainly include: math.constants, integer, rational, ratio, CRC and RANDOM6 libraries.
(1) Math.constants library: mainly contains some mathematical constants, such as square root 2, pi and so on;
(2) Integer library: To provide yo tube integer processing of the header files and classes, with good portability;
(3) Rational Library: realization of rational number
(4) Ratio Library: the expression of some commonly used units in life;
(5) CRC Library: is the computer network in the cyclic redundancy check code, is a kind of error detection mechanism;
(6) Random library: Real random number generator.

9. Operating system related
Boost provides a range of Cross-platform porting capabilities that block the underlying details of the operating system, including system, Chrono, Cpu_timer, filesystem, program_options libraries;
(1) System library: Use lightweight objects to encapsulate error codes and error messages at the bottom of the operating system so that programs that invoke operating system functionality can be easily ported to other systems.
(2) Cpu_timer Library: Support the timing of high progress of CPU time slice;
(3) FileSystem Library: is a portable file system operation Library;

            (4) Program_options Library: Provides powerful command-line parameter processing capabilities similar to GCC;

    10, Functions and callbacks
        mainly involved functions and function objects, a total of 4 libraries: REF, BIND, function, SIGNALS2
            (1) Ref library: Providing referential semantics;
            (2) Bind library: Provide parameter binding function
      &NB Sp     (3) function library: Functions Object "container"
            (4) SIGNALS2 Library: Based on another library in the boost library signals implement the thread-safe observer mode;

    11, concurrent programming
        Boost provides a number of libraries or components for concurrent programming to make up for C + + standard library in a short board, consisting mainly of 3 libraries: Atomic, thread, ASIO.
            (1) Atomic library: Implements the yard operation library defined by the C++11 standard library, encapsulates the underlying operating primitives of different computer hardware, and provides a cross-platform atomic operation function;
& nbsp           (2) Thread Library: has become the standard of c++11, added to C + + threading capabilities, it provides a concise and clear mutex, thread, condition variables and other concepts, can easily create multithreaded applications, Implement concurrent programming.
            (3) ASIO library: Mainly for network programming, encapsulating a large number of socket APIs, providing a modern C + +-style Network programming interface

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.