Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Beyond Basic Conversions

An interesting (and yet to be fully explored) property of the described design is that Boost.Convert is not limited to string-to-type and type-to-string conversions. The boost::convert() interface is type-agnostic and the plugged-in converter ultimately dictates what type transformations are available. Consequently, a wide range of conversion/transformation-related tasks can be addressed and deployed uniformly by plugging-in special-purpose converters.

As an experiment, the code below (taken from test/encryption.cpp) does not do type conversion. Instead, it applies a string transformation:

string encrypted = boost::convert<string>("ABC", my_cypher).value();
string decrypted = boost::convert<string>(encrypted, my_cypher).value();

BOOST_ASSERT(encrypted == "123");
BOOST_ASSERT(decrypted == "ABC");

The original "ABC" string is "encrypted" as "123" first and then "123" is "decrypted" back to its original "ABC" form.

Similarly, I personally do not immediately see as objectionable string-transformations like:

std::u8string utf8 = boost::convert<std::u8string>(utf32_str, cnv);
std::u8string utf8 = boost::convert<std::u8string>(mbcs_str, cnv);

PrevUpHomeNext