In this blog we will discuss about Boot Library in C++ 11. Boost is a set of libraries for the C++ programming language that provide support for tasks and structures such as pseudo random number generation, linear algebra, image processing, multi-threading, regular expressions, and unit testing. It contains eighty plus individual libraries, most of the Boost libraries are licensed under the Boost Software License, designed to allow Boost to be used with both free and proprietary software projects.
Advantages of Boost library :
- Open Source Library.
- Cross Platform Development.
- STL library support available.
- Well documented, document available on www.boost.org
- Good execution performance.
- Easy and readable coding possible with boost library.
Installation procedure of boost :
Use this link for installation :
- Unix : Getting Started on Unix
- Windows : Getting Started on Windows
What Does Boost Provide?
Smart Pointers: There are some limitation of std::auto_ptr's like - cannot be stored within a standard containers, cannot be used to implement the pImpl (pointer-to-implementation) idiom and also does not work with arrays. In Boost library 5 type for smart pointers created to overcome this problem.
Any : In C++ 11 auto datatype is created , but auto we can use only inside function, to pass as function parameter auto can't be useful. Boost::any is more power full than Auto. Any is useful when you are working with design pattern.
Bind and Function : boost::bind and boost::function are specified as two separate components, but they are extensions (any number of arguments) of binders and functors concept which are currently in place in the Standard Library.
The Lambda Library : Powerful lambda library is provided by boost to work with boost::bind and boost::function.
The Boost Graph Library : The Boost Graph Library is a huge library, with a large amount of support material and good sample programs.
Thread : The threads library makes it seem almost as easy to do threads in C++ .
Spirit parser generator framework : Parser framework is added to work with XML.
What Else?
- Regular Expressions
- Traits
- File System
- Iterator Adaptors
- Maths and Matrices
- A Template metaprogramming framework
- Tuples
- Python
Simple Program using Boost Library :
1)
#include <iostream> #include "boost/any.hpp" int main() { boost::any var1 = 5; std::cout << boost::any_cast<int>(var1) <<std::endl; int i = boost::any_cast<int>(var1); std::cout << i <<std::endl; return 0; }
2)
//It will cause boost::bad_any_cast exception, #include <iostream> #include "boost/any.hpp" int main() { try { boost::any var1 = 5; std::cout << boost::any_cast<std::string>(var1) <<std::endl; } catch(boost::bad_any_cast &e) { std::cout << e.what() << std::endl; } return 0; }
boost::bad_any_cast: failed conversion using boost::any_cast
No comments:
Post a Comment