]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/convert/doc/algorithms.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / convert / doc / algorithms.qbk
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
7 [section:algorithms Boost.Convert with Standard Algorithms]
8
9 [algorithm_example1]
10 [algorithm_example2]
11 [algorithm_example3]
12 [algorithm_example4]
13 [algorithm_example5]
14
15 [heading Forced ['TypeIn] vs. Deduced]
16
17 So far it was sufficient to explicitly specify only one type to `boost::cnv::apply<TypeOut>` -- the target ['TypeOut] type. The source ['TypeIn] type has been provided implicitly through the algorithm and often it all just works (as the examples above demonstrate). However, at times more control is needed regarding the ['TypeIn] type and `boost::cnv::apply()` provides such control via explicit specification of ['TypeIn] -- `boost::cnv::apply<TypeOut, TypeIn>`.
18
19 The following example demonstrates an interesting issue related to the ['`change`] class introduced in [link boost_convert.integration_of_user_types Integration of User-Defined Types]. The class is essentially a glorified ['`enum`], a user-friendly convenience wrapper around the actual ['`enum value_type { no, up, dn }`]. In the example an array of ['`change`] values (`chgs1`) is sensibly converted to readable "no", "up" and "dn" strings (`strs1`) when an array of ['`change::value_type`] values (`chgs2`) converts to obscure "0", "1" and "2" (`strs2`).
20
21 [algorithm_example6]
22
23 The `boost::cnv::apply<TypeOut, TypeIn>` with forced (rather than deduced) ['TypeIn] comes to the rescue and converts the array of ['`change::value_type`] values (`chgs2`) to sensible "no", "up" and "dn" (`strs3`):
24
25 [algorithm_example7]
26
27 [note For demonstration purposes the example above is made as simple as possible and, consequently, the described "issue" could probably be addressed by other means. Still, do not let my inability to come up with a better (complex but short and succulent) example get in the way of appreciating the described functionality. I do not expect it to be used often but it is here when you need it.]
28
29 [endsect] [/section:algorithms Boost.Convert with Standard Algorithms]
30