Although boost: scoped_ptr is easy to use, its ability to share ownership is greatly limited, while boost: shared_ptr can solve this limitation. As the name implies, boost: shared_ptr is a smart pointer that can share ownership. First, let's look at its basic usage through an example:
#include
The output result of this program is as follows:
The sample now has
Try to use sprintf as little as possible, and do not know when the program crashes.
Http://www.cnblogs.com/WuErPIng/archive/2005/04/21/142308.aspxTry boost format
1. Boost: Format Basic Syntax: boost: Format (format-string) % arg1 % arg2 %... % argnThe following example shows how to use boost: Format// Method 1
Cout
Try boost format
Http://www.cnblogs.com/wuerping/archive/2005/04/21/142308.html
Overview
STD: string is a good stuff, but in actual use, basically encounter unpleasant things in every program: format the string. MeEven for this reason, we can introduce platform-related MFC, ATL, and other heavyweight frameworks that do not need to be used in the project to easily format strings.. I tried to extract the format function of ATL: cstring and use it. Howe
This article mainly introduces the use of smart pointers in boost. (Transferred from: http://www.cnblogs.com/sld666666/archive/2010/12/16/1908265.html)Memory management is a tedious issue, with two implementations in C + +: Garbage collection mechanism and smart pointers. Garbage collection mechanism because of performance and other reasons are not respected by C + +, and smart pointers are considered to solve the C + + memory problem of the best solu
First , create a thread
Creating Threads
Boost::thread mythread (Threadfun);
Note that the parameter can be a function object or a function pointer. And this function has no arguments and returns the void type .
When a thread execution completes, the child thread disappears. Note that this thread object will not disappear, it is still a C + + object that is still in its lifetime. Similarly, when a pointer to a thread object on a heap calls delete, th
Overview of Boost Locks:
The mutex class and lock class are provided in the Boost library, and can be easily constructed by combining read-write and mutex locks.
For example, if the shared resource is an automatically locked room, the mutex is the key, the key must be taken into the room, and the key should be left out of the room. This corresponds to the lock of the mutex (the key) and the unlock (the key)
Bind-boost
Header file: boost/bind.hpp
Bind is a set of overloaded function templates.Used to bind certain parameters to a function (or function object).The return value of BIND is a function object.
Its source file is too long. Can't look down. Here, just write down its usage:
9.1 For normal functions
If there is a function fun () as follows:void Fun (int x, int y) {cout }Now let's see how to bind paramete
4. Boost. Lambda
Anonymous functions, also known as Lambda functions, already exist in multiple programming languages, except C ++. However, with the help of the boost. Lambda library, they can be used in C ++ applications.
Lambda functions are designed to make the source code more compact and easier to understand. Take the code example in Section 1 of this chapter as an example.
#include
This program acce
Bind-boost
Header file: boost/Bind. HPP
BindIs a set of overloaded function templates.Used to bind certain parameters to a function (or function object.The return value of BIND is a function object.
Its source file is too long. You can't see it. Here we only write down its usage:
9.1 for common functions
Assume that the function fun () is as follows:Void fun (int x, int y){Cout }Now let's look at
Recently in a message middleware involved in multithreaded programming, because of cross-platform reasons I used the Boost line libraries. Several thread creation methods are encountered when creating a thread, as summarized below:First look at Boost::thread's constructor, Boost::thread has two constructors:(1) thread (): Constructs a thread object that represent
This blog (http://blog.csdn.net/livelylittlefish) Post author (three two one @ fish) related research, learning content made notes, welcome to the majority of friends correct!
How to compile boost on Linux
Boost compilation uses the bjam (boost JAM) tool specially developed for Boost instead of making, which has bec
Use the boost: iostreams library to compress and decompress data.-Bo Cheng's blog-blog channel-csdn. net
Use the boost: iostreams library to compress and decompress data
Category: boost
92 people reading
Comment (0)
Favorites
Report Boostboostiostreams
In today's project, we are going to use gzip to compress the data and find the
Shared pointersThis smart pointer is named BOOST::SHARED_PTR, defined in BOOST/SHARED_PTR.HPP. The smart pointer boost::shared_ptr is basically similar to boost::scoped_ptr. The key difference is that BOOST::SHARED_PTR does not necessarily have to monopolize an object. It ca
Ubuntu 15.04 can already be installed directly through the Apt-get Insall clang 3.6, and the pre-installed GCC version is 4.9.2. These installation procedures are described here.First download the boost source code[Plain]View PlainCopyprint?
Wget-o boost.1.59.tar.bz2 Http://sourceforge.net/projects/boost/files/latest/download?source=files
Extract[Pl
Address: http://www.cnblogs.com/TianFang/archive/2008/09/29/1301880.html Boost Conversion Function (2)
Boost: numeric_cast
In C ++, we often need to convert different types of numbers, such as converting a number between long and short. However, because the precision of each number is different, the conversion may fail if a number is of the "big" type to "small" type, as shown below:
LongN1 =
Boost: thread has two constructors:(1) thread (): constructs a thread object that represents the current execution thread;(2) Explicit thread (const boost: function0 Boost: function0 Method 1: the simplest method# Include # Include
Void Hello (){STD: cout "Hello world, I ''m a thread! "}
Int main (INT argc, char * argv []){B
1. Mutex Object classThere are two main types of mutex classes: exclusive and shared mutex.▲ Exclusive Mutex Amount:Mutex: Exclusive mutex, which is the simplest and most common type of mutexTry_mutex: It is a synonym for a mutex, provided for compatibility with previous versionsTimed_mutex: It is also an exclusive mutex, but provides a timeout lock feature▲ Recursive mutual-exclusion amount:Recursive_mutex: Recursive mutex, can be locked multiple times, corresponding to the number of unlockedRe
1 IntroductionBoost is a quasi-C + + standard library, equivalent to the continuation and expansion of STL, its design concept and STL are relatively close to the use of generics to maximize reuse. Boost includes several broad categories: string and text processing, containers, iterators (iterator), algorithms, function objects and higher-order programming, generic programming, template meta-programming, preprocessing meta-programming, concurrent prog
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.