SlideShare une entreprise Scribd logo
1  sur  10
Let’s Take A Look At The
Boost Libraries
Seoul System Programmers Network #6
@TomSmartBishop Thomas Pollak
Setup Boost (currently v1.61)
 Download and unzip (http://www.boost.org/users/download/)
 Run bootstrap(.bat|.sh)
 Run b2 to generate the libs for your toolchain
 Without parameters b2 will try to auto-detect your toolchain
 In case you would like to build for another platform or b2 has troubles use --help to
see all options
 Libs will be in the sub directory stage/lib, you can move/install everything to the
default locations with b2 install
Let’s look at the samples
 You can find the source code here:
https://github.com/TomSmartBishop/sspn_06_lets_boost
 I picked 7 boost libraries that I found interesting and used some more as little helpers,
but there is much more: http://www.boost.org/users/history/version_1_61_0.html
 Most libraries are header only and make heavy use of templates (and macros). Samples
that need library linkage are pointed out on the slides.
 Be aware that there s a compile time overhead, also for small samples.
 Due to the fact that most boost libraries have different authors the API seems not always
homogenous (however there are core components used across all libs).
 Sometimes the API feels sometimes a bit over-engineered but does work as expected
(compared to the STL lib).
 In VS2015 /Wall produces a lot warnings so that /W4 seems like a better choice.
Boost Program Options
http://www.boost.org/doc/libs/1_61_0/doc/html/program_options.html
 In case you are writing a program with command line parameters this is quite useful.
No need to re-implement boring stuff again and again. The github sample uses the
program options also to switch between the other sample implementations.
 Needs to be linked against the program_options library.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level");
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("help"))
cout << desc << "n";
else if (vm.count("compression"))
cout << "Compression level was set to " << vm["compression"].as<int>() << ".n";
else
cout << "Compression level was not set.n";
Boost Any
http://www.boost.org/doc/libs/1_61_0/doc/html/any.html
 This behaves more or less what we know from Java and C# as “object”. It uses a
template class to store the exact type you using. Therefore no implicit conversions,
if you assign 5, the type will be an int and if you assign 5.0 it will be a double.
Boost Any is really handy and interestingly has been described in a paper back in
the year 2000, however it’s not part of the STL (would be nice though).
std::vector<boost::any> values;
values.push_back(std::string("Hello"));
values.push_back("World");
values.push_back(42);
values.push_back(3.14f);
Boost Variant
http://www.boost.org/doc/libs/1_61_0/doc/html/variant.html
 Similar to Any, but Variant accepts only the predefined types. So it looks more like
a union, but without the drawback of a union.
Drawbacks of a union?
 You can access a union at any time with any variation, eg. access the a float’s data as an
int and this behavior is not defined in the standard. The standard only specified
subsequent access of the same variant. Interestingly this is supported by most compilers
(at least MSVC, clang, GCC) and is actually used in real world applications to access the
bit representation of floating point number (or similar).
 Only POD types allowed, but boost Variant also allows non PODs so we can create a
variant like this: boost::variant< int, std::string > var("hello world");
Boost Lexical Cast
http://www.boost.org/doc/libs/1_61_0/doc/html/boost_lexical_cast.html
 Convenient type conversion, no more need for atoi or sprintf to convert from
int to string or the other way around.
 Supports all fundamental C++ types and much more convenient compared to
std::strtol and similar: int32_t i = lexical_cast<int32_t>("42");
 Heap allocation can be avoided if desired (when converting to string).
Boost Signals2
http://www.boost.org/doc/libs/1_61_0/doc/html/signals2.html
 Callbacks with multiple targets. Comparable with event listeners in Java (without
interfaces).
 The callback receivers are called “slots” which are invoked by the “signal”.
struct HelloWorld
{
void operator()() const { cout << "Hello, World!n"; }
};
// Signal with no arguments and a void return value
boost::signals2::signal<void ()> sig;
// Connect a HelloWorld slot
HelloWorld hello;
sig.connect(hello);
// Call all of the slots
sig();
Boost Serialization
http://www.boost.org/doc/libs/1_61_0/libs/serialization/doc/index.html
 Easy serialization, even though I cannot speak of a large scale experience, the interface
looks good and I couldn’t spot any obvious pitfalls.
 Can handle STL containers and as far as I could see also other boost classes like
boost::greogorian::date.
 Can restore pointers (serializes the content, not the pointer).
 Needs to be linked against the serialization library
(as well as the chrono/date_time library).
 Uses RTTI by default, but also can be used without RTTI (with some typing overhead).
Boost Compute
http://www.boost.org/doc/libs/1_61_0/libs/compute/doc/html/index.html
 Compute is one of the latest additions to boost. In my small samples I also got
two warning during “normal” API usage, which I could fix by myself by doing some
explicit type casts in the library’s header, so it looks like it needs still some time to
really get stable.
 However the concept is quite interesting: You can use your GPU to perform
computations and the API let’s you do that in a very convenient way without
worrying about the underlying hardware or compute shaders.
 I didn’t perform any tests how much that can speedup operations, so I still need
some more time to play around and explore…

Contenu connexe

Tendances

Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
Mohammed Farrag
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn Workshop
Bastian Feder
 
Linux multiplexing
Linux multiplexingLinux multiplexing
Linux multiplexing
Mark Veltzer
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
julien pauli
 

Tendances (20)

Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
 
Shell Script Linux
Shell Script LinuxShell Script Linux
Shell Script Linux
 
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin PiebiakWorkflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
 
Workflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large EnterprisesWorkflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large Enterprises
 
LibreSSL
LibreSSLLibreSSL
LibreSSL
 
Operating System Assignment Help
Operating System Assignment HelpOperating System Assignment Help
Operating System Assignment Help
 
Instruction: dev environment
Instruction: dev environmentInstruction: dev environment
Instruction: dev environment
 
Angular 1.6 typescript application
Angular 1.6 typescript applicationAngular 1.6 typescript application
Angular 1.6 typescript application
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn Workshop
 
Linux multiplexing
Linux multiplexingLinux multiplexing
Linux multiplexing
 
Shell script-sec
Shell script-secShell script-sec
Shell script-sec
 
Shellprogramming
ShellprogrammingShellprogramming
Shellprogramming
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
unix-OS-Lab-4.doc
unix-OS-Lab-4.docunix-OS-Lab-4.doc
unix-OS-Lab-4.doc
 
Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
 
Runtime surgery
Runtime surgeryRuntime surgery
Runtime surgery
 
BitTorrent on iOS
BitTorrent on iOSBitTorrent on iOS
BitTorrent on iOS
 
Documentation with sphinx @ PyHug
Documentation with sphinx @ PyHugDocumentation with sphinx @ PyHug
Documentation with sphinx @ PyHug
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
 
3.1.c apend scripting, crond, atd
3.1.c apend   scripting, crond, atd3.1.c apend   scripting, crond, atd
3.1.c apend scripting, crond, atd
 

En vedette

Search Presentation
Search  PresentationSearch  Presentation
Search Presentation
Doug Green
 

En vedette (8)

Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++
 
Boost C++ Libraries
Boost C++ LibrariesBoost C++ Libraries
Boost C++ Libraries
 
Руслан Муллахметов, Открытый и неинтрузивный менеджер зависимостей для С++
Руслан Муллахметов, Открытый и неинтрузивный менеджер зависимостей для С++Руслан Муллахметов, Открытый и неинтрузивный менеджер зависимостей для С++
Руслан Муллахметов, Открытый и неинтрузивный менеджер зависимостей для С++
 
Илья Шишков, Принципы создания тестируемого кода
Илья Шишков, Принципы создания тестируемого кодаИлья Шишков, Принципы создания тестируемого кода
Илья Шишков, Принципы создания тестируемого кода
 
XPath for web scraping
XPath for web scrapingXPath for web scraping
XPath for web scraping
 
Фитнес для вашего кода: как держать его в форме
Фитнес для вашего кода: как держать его в формеФитнес для вашего кода: как держать его в форме
Фитнес для вашего кода: как держать его в форме
 
Search Presentation
Search  PresentationSearch  Presentation
Search Presentation
 
3689[1].pdf
3689[1].pdf3689[1].pdf
3689[1].pdf
 

Similaire à Let's Take A Look At The Boost Libraries

BACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docxBACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docx
wilcockiris
 

Similaire à Let's Take A Look At The Boost Libraries (20)

Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
C Under Linux
C Under LinuxC Under Linux
C Under Linux
 
Rasperry pi Part 8
Rasperry pi Part 8Rasperry pi Part 8
Rasperry pi Part 8
 
Readme
ReadmeReadme
Readme
 
Book
BookBook
Book
 
Mach-O Internals
Mach-O InternalsMach-O Internals
Mach-O Internals
 
Advanced Rational Robot A Tribute (http://www.geektester.blogspot.com)
Advanced Rational Robot   A Tribute (http://www.geektester.blogspot.com)Advanced Rational Robot   A Tribute (http://www.geektester.blogspot.com)
Advanced Rational Robot A Tribute (http://www.geektester.blogspot.com)
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
BACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docxBACKGROUND A shell provides a command-line interface for users. I.docx
BACKGROUND A shell provides a command-line interface for users. I.docx
 
C++ development within OOo
C++ development within OOoC++ development within OOo
C++ development within OOo
 
CoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdCoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love Systemd
 
mblock_extension_guide.pdf
mblock_extension_guide.pdfmblock_extension_guide.pdf
mblock_extension_guide.pdf
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
GWT 2 Is Smarter Than You
GWT 2 Is Smarter Than YouGWT 2 Is Smarter Than You
GWT 2 Is Smarter Than You
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 
C++ Boot Camp Part 2
C++ Boot Camp Part 2C++ Boot Camp Part 2
C++ Boot Camp Part 2
 
Usage Note of SWIG for PHP
Usage Note of SWIG for PHPUsage Note of SWIG for PHP
Usage Note of SWIG for PHP
 
ARM Embeded_Firmware.pdf
ARM Embeded_Firmware.pdfARM Embeded_Firmware.pdf
ARM Embeded_Firmware.pdf
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Let's Take A Look At The Boost Libraries

  • 1. Let’s Take A Look At The Boost Libraries Seoul System Programmers Network #6 @TomSmartBishop Thomas Pollak
  • 2. Setup Boost (currently v1.61)  Download and unzip (http://www.boost.org/users/download/)  Run bootstrap(.bat|.sh)  Run b2 to generate the libs for your toolchain  Without parameters b2 will try to auto-detect your toolchain  In case you would like to build for another platform or b2 has troubles use --help to see all options  Libs will be in the sub directory stage/lib, you can move/install everything to the default locations with b2 install
  • 3. Let’s look at the samples  You can find the source code here: https://github.com/TomSmartBishop/sspn_06_lets_boost  I picked 7 boost libraries that I found interesting and used some more as little helpers, but there is much more: http://www.boost.org/users/history/version_1_61_0.html  Most libraries are header only and make heavy use of templates (and macros). Samples that need library linkage are pointed out on the slides.  Be aware that there s a compile time overhead, also for small samples.  Due to the fact that most boost libraries have different authors the API seems not always homogenous (however there are core components used across all libs).  Sometimes the API feels sometimes a bit over-engineered but does work as expected (compared to the STL lib).  In VS2015 /Wall produces a lot warnings so that /W4 seems like a better choice.
  • 4. Boost Program Options http://www.boost.org/doc/libs/1_61_0/doc/html/program_options.html  In case you are writing a program with command line parameters this is quite useful. No need to re-implement boring stuff again and again. The github sample uses the program options also to switch between the other sample implementations.  Needs to be linked against the program_options library. po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value<int>(), "set compression level"); po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); po::notify(vm); if (vm.count("help")) cout << desc << "n"; else if (vm.count("compression")) cout << "Compression level was set to " << vm["compression"].as<int>() << ".n"; else cout << "Compression level was not set.n";
  • 5. Boost Any http://www.boost.org/doc/libs/1_61_0/doc/html/any.html  This behaves more or less what we know from Java and C# as “object”. It uses a template class to store the exact type you using. Therefore no implicit conversions, if you assign 5, the type will be an int and if you assign 5.0 it will be a double. Boost Any is really handy and interestingly has been described in a paper back in the year 2000, however it’s not part of the STL (would be nice though). std::vector<boost::any> values; values.push_back(std::string("Hello")); values.push_back("World"); values.push_back(42); values.push_back(3.14f);
  • 6. Boost Variant http://www.boost.org/doc/libs/1_61_0/doc/html/variant.html  Similar to Any, but Variant accepts only the predefined types. So it looks more like a union, but without the drawback of a union. Drawbacks of a union?  You can access a union at any time with any variation, eg. access the a float’s data as an int and this behavior is not defined in the standard. The standard only specified subsequent access of the same variant. Interestingly this is supported by most compilers (at least MSVC, clang, GCC) and is actually used in real world applications to access the bit representation of floating point number (or similar).  Only POD types allowed, but boost Variant also allows non PODs so we can create a variant like this: boost::variant< int, std::string > var("hello world");
  • 7. Boost Lexical Cast http://www.boost.org/doc/libs/1_61_0/doc/html/boost_lexical_cast.html  Convenient type conversion, no more need for atoi or sprintf to convert from int to string or the other way around.  Supports all fundamental C++ types and much more convenient compared to std::strtol and similar: int32_t i = lexical_cast<int32_t>("42");  Heap allocation can be avoided if desired (when converting to string).
  • 8. Boost Signals2 http://www.boost.org/doc/libs/1_61_0/doc/html/signals2.html  Callbacks with multiple targets. Comparable with event listeners in Java (without interfaces).  The callback receivers are called “slots” which are invoked by the “signal”. struct HelloWorld { void operator()() const { cout << "Hello, World!n"; } }; // Signal with no arguments and a void return value boost::signals2::signal<void ()> sig; // Connect a HelloWorld slot HelloWorld hello; sig.connect(hello); // Call all of the slots sig();
  • 9. Boost Serialization http://www.boost.org/doc/libs/1_61_0/libs/serialization/doc/index.html  Easy serialization, even though I cannot speak of a large scale experience, the interface looks good and I couldn’t spot any obvious pitfalls.  Can handle STL containers and as far as I could see also other boost classes like boost::greogorian::date.  Can restore pointers (serializes the content, not the pointer).  Needs to be linked against the serialization library (as well as the chrono/date_time library).  Uses RTTI by default, but also can be used without RTTI (with some typing overhead).
  • 10. Boost Compute http://www.boost.org/doc/libs/1_61_0/libs/compute/doc/html/index.html  Compute is one of the latest additions to boost. In my small samples I also got two warning during “normal” API usage, which I could fix by myself by doing some explicit type casts in the library’s header, so it looks like it needs still some time to really get stable.  However the concept is quite interesting: You can use your GPU to perform computations and the API let’s you do that in a very convenient way without worrying about the underlying hardware or compute shaders.  I didn’t perform any tests how much that can speedup operations, so I still need some more time to play around and explore…