1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Beyond Basic Conversions</title> 5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../index.html" title="Chapter 1. Boost.Convert 2.0"> 8<link rel="up" href="../index.html" title="Chapter 1. Boost.Convert 2.0"> 9<link rel="prev" href="performance/the_bigger_picture.html" title="The Bigger Picture"> 10<link rel="next" href="converters_detail.html" title="Converters in Detail"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="performance/the_bigger_picture.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="converters_detail.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 27<a name="boost_convert.other_conversions"></a><a class="link" href="other_conversions.html" title="Beyond Basic Conversions">Beyond Basic Conversions</a> 28</h2></div></div></div> 29<p> 30 An interesting (and yet to be fully explored) property of the described design 31 is that <span class="emphasis"><em>Boost.Convert</em></span> is not limited to string-to-type 32 and type-to-string conversions. The <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special">()</span></code> interface is type-agnostic and the plugged-in 33 converter ultimately dictates what type transformations are available. Consequently, 34 a wide range of conversion/transformation-related tasks can be addressed and 35 <span class="emphasis"><em>deployed uniformly</em></span> by plugging-in special-purpose converters. 36 </p> 37<p> 38 As an experiment, the code below (taken from <span class="emphasis"><em>test/encryption.cpp</em></span>) 39 does not do type conversion. Instead, it applies a string transformation: 40 </p> 41<pre class="programlisting"><span class="identifier">string</span> <span class="identifier">encrypted</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special"><</span><span class="identifier">string</span><span class="special">>(</span><span class="string">"ABC"</span><span class="special">,</span> <span class="identifier">my_cypher</span><span class="special">).</span><span class="identifier">value</span><span class="special">();</span> 42<span class="identifier">string</span> <span class="identifier">decrypted</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special"><</span><span class="identifier">string</span><span class="special">>(</span><span class="identifier">encrypted</span><span class="special">,</span> <span class="identifier">my_cypher</span><span class="special">).</span><span class="identifier">value</span><span class="special">();</span> 43 44<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">encrypted</span> <span class="special">==</span> <span class="string">"123"</span><span class="special">);</span> 45<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">decrypted</span> <span class="special">==</span> <span class="string">"ABC"</span><span class="special">);</span> 46</pre> 47<p> 48 The original "ABC" string is "encrypted" as "123" 49 first and then "123" is "decrypted" back to its original 50 "ABC" form. 51 </p> 52<p> 53 Similarly, I personally do not immediately see as objectionable string-transformations 54 like: 55 </p> 56<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span> <span class="identifier">utf8</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span><span class="special">>(</span><span class="identifier">utf32_str</span><span class="special">,</span> <span class="identifier">cnv</span><span class="special">);</span> 57<span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span> <span class="identifier">utf8</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">convert</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">u8string</span><span class="special">>(</span><span class="identifier">mbcs_str</span><span class="special">,</span> <span class="identifier">cnv</span><span class="special">);</span> 58</pre> 59</div> 60<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 61<td align="left"></td> 62<td align="right"><div class="copyright-footer">Copyright © 2009-2016 Vladimir Batov<p> 63 Distributed under the Boost Software License, Version 1.0. See copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>. 64 </p> 65</div></td> 66</tr></table> 67<hr> 68<div class="spirit-nav"> 69<a accesskey="p" href="performance/the_bigger_picture.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="converters_detail.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 70</div> 71</body> 72</html> 73