O'Reilly logo

Boost C++ Application Development Cookbook by Antony Polukhin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using a safer way to work with a container that stores multiple chosen types

Imagine that you are creating a wrapper around some SQL database interface. You decided that boost::any will perfectly match the requirements for a single cell of the database table. Some other programmer will be using your classes, and his task would be to get a row from the database and count the sum of the arithmetic types in a row.

Here's how the code would look:

#include <boost/any.hpp> #include <vector> #include <string> #include <typeinfo> #include <algorithm> #include <iostream> // This typedefs and methods will be in our header, // that wraps around native SQL interface typedef boost::any cell_t; typedef std::vector<cell_t> db_row_t; // This is just an example, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required