This recipe and the next one are devoted to a mix of compile time and runtime features. We'll be using the Boost.Fusion
library and see what it can do.
Remember that we were talking about tuples and arrays in the first chapter? Now, we want to write a single function that can stream elements of tuples and arrays to strings.
You should be aware of the boost::tuple
and boost::array
classes and of the boost::lexical_cast
function.
We already know almost all the functions and classes that will be used in this recipe. We just need to gather all of them together:
- We need to write a functor that converts any type to string:
#include <boost/lexical_cast.hpp> #include <boost/noncopyable.hpp> struct stringize_functor: boost::noncopyable { private: std::string& result; public: explicit stringize_functor(std::string& res) : result(res) {} template <class T> void operator()(const...