1234567891011121314151617181920212223242526 |
- [/
- Copyright (c) Vladimir Batov 2009-2016
- Distributed under the Boost Software License, Version 1.0.
- See copy at http://www.boost.org/LICENSE_1_0.txt.
- ]
- [section:other_conversions 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);
- [endsect]
|