Blame view

3rdparty/boost_1_81_0/libs/convert/doc/other.qbk 1.37 KB
977ed18d   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  [/
    Copyright (c) Vladimir Batov 2009-2022
    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]