other.qbk 1.4 KB

1234567891011121314151617181920212223242526
  1. [/
  2. Copyright (c) Vladimir Batov 2009-2016
  3. Distributed under the Boost Software License, Version 1.0.
  4. See copy at http://www.boost.org/LICENSE_1_0.txt.
  5. ]
  6. [section:other_conversions Beyond Basic Conversions]
  7. 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.
  8. As an experiment, the code below (taken from ['test/encryption.cpp]) does not do type conversion. Instead, it applies a string transformation:
  9. string encrypted = boost::convert<string>("ABC", my_cypher).value();
  10. string decrypted = boost::convert<string>(encrypted, my_cypher).value();
  11. BOOST_ASSERT(encrypted == "123");
  12. BOOST_ASSERT(decrypted == "ABC");
  13. The original "ABC" string is "encrypted" as "123" first and then "123" is "decrypted" back to its original "ABC" form.
  14. Similarly, I personally do not immediately see as objectionable string-transformations like:
  15. std::u8string utf8 = boost::convert<std::u8string>(utf32_str, cnv);
  16. std::u8string utf8 = boost::convert<std::u8string>(mbcs_str, cnv);
  17. [endsect]