1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Boost.Fusion</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. Geometry"> 8<link rel="up" href="../adapted.html" title="Adapted models"> 9<link rel="prev" href="boost_array.html" title="Boost.Array"> 10<link rel="next" href="boost_tuple.html" title="Boost.Tuple"> 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="boost_array.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../adapted.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="boost_tuple.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="geometry.reference.adapted.boost_fusion"></a><a class="link" href="boost_fusion.html" title="Boost.Fusion">Boost.Fusion</a> 28</h4></div></div></div> 29<p> 30 Boost.Fusion adapted structs or classes are adapted to the Boost.Geometry 31 point concept 32 </p> 33<h6> 34<a name="geometry.reference.adapted.boost_fusion.h0"></a> 35 <span class="phrase"><a name="geometry.reference.adapted.boost_fusion.description"></a></span><a class="link" href="boost_fusion.html#geometry.reference.adapted.boost_fusion.description">Description</a> 36 </h6> 37<p> 38 Boost.Fusion adapted structs are (optionally) adapted to the Boost.Geometry 39 point concept. They can therefore be used in many Boost.Geometry algorithms. 40 </p> 41<h6> 42<a name="geometry.reference.adapted.boost_fusion.h1"></a> 43 <span class="phrase"><a name="geometry.reference.adapted.boost_fusion.model_of"></a></span><a class="link" href="boost_fusion.html#geometry.reference.adapted.boost_fusion.model_of">Model 44 of</a> 45 </h6> 46<p> 47 <a class="link" href="../concepts/concept_point.html" title="Point Concept">Point Concept</a> 48 </p> 49<h6> 50<a name="geometry.reference.adapted.boost_fusion.h2"></a> 51 <span class="phrase"><a name="geometry.reference.adapted.boost_fusion.header"></a></span><a class="link" href="boost_fusion.html#geometry.reference.adapted.boost_fusion.header">Header</a> 52 </h6> 53<p> 54 <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">adapted</span><span class="special">/</span><span class="identifier">boost_fusion</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 55 </p> 56<p> 57 The standard header <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span></code> 58 does not include this header. 59 </p> 60<h6> 61<a name="geometry.reference.adapted.boost_fusion.h3"></a> 62 <span class="phrase"><a name="geometry.reference.adapted.boost_fusion.example"></a></span><a class="link" href="boost_fusion.html#geometry.reference.adapted.boost_fusion.example">Example</a> 63 </h6> 64<p> 65 Shows how to combine Boost.Fusion with Boost.Geometry 66 </p> 67<p> 68</p> 69<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 70 71<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">adapt_struct_named</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 72 73<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 74<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">adapted</span><span class="special">/</span><span class="identifier">boost_fusion</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 75 76 77<span class="keyword">struct</span> <span class="identifier">sample_point</span> 78<span class="special">{</span> 79 <span class="keyword">double</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">,</span> <span class="identifier">z</span><span class="special">;</span> 80<span class="special">};</span> 81 82<span class="identifier">BOOST_FUSION_ADAPT_STRUCT</span><span class="special">(</span><span class="identifier">sample_point</span><span class="special">,</span> <span class="special">(</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">(</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">(</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">z</span><span class="special">))</span> 83<span class="identifier">BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS</span><span class="special">(</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">)</span> 84 85<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 86<span class="special">{</span> 87 <span class="identifier">sample_point</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">c</span><span class="special">;</span> 88 89 <span class="comment">// Set coordinates the Boost.Geometry way (one of the ways)</span> 90 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">assign_values</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="number">3</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span> 91 92 <span class="comment">// Set coordinates the Boost.Fusion way</span> 93 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">at_c</span><span class="special"><</span><span class="number">0</span><span class="special">>(</span><span class="identifier">b</span><span class="special">)</span> <span class="special">=</span> <span class="number">6</span><span class="special">;</span> 94 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">at_c</span><span class="special"><</span><span class="number">1</span><span class="special">>(</span><span class="identifier">b</span><span class="special">)</span> <span class="special">=</span> <span class="number">5</span><span class="special">;</span> 95 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">at_c</span><span class="special"><</span><span class="number">2</span><span class="special">>(</span><span class="identifier">b</span><span class="special">)</span> <span class="special">=</span> <span class="number">4</span><span class="special">;</span> 96 97 <span class="comment">// Set coordinates the native way</span> 98 <span class="identifier">c</span><span class="special">.</span><span class="identifier">x</span> <span class="special">=</span> <span class="number">9</span><span class="special">;</span> 99 <span class="identifier">c</span><span class="special">.</span><span class="identifier">y</span> <span class="special">=</span> <span class="number">8</span><span class="special">;</span> 100 <span class="identifier">c</span><span class="special">.</span><span class="identifier">z</span> <span class="special">=</span> <span class="number">7</span><span class="special">;</span> 101 102 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Distance a-b: "</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 103 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Distance a-c: "</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">c</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 104 105 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 106<span class="special">}</span> 107</pre> 108<p> 109 </p> 110<p> 111 Output: 112 </p> 113<pre class="programlisting">Distance a-b: 5.19615 114Distance a-c: 10.3923 115</pre> 116</div> 117<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 118<td align="left"></td> 119<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 120 Wulkiewicz, Oracle and/or its affiliates<p> 121 Distributed under the Boost Software License, Version 1.0. (See accompanying 122 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 123 </p> 124</div></td> 125</tr></table> 126<hr> 127<div class="spirit-nav"> 128<a accesskey="p" href="boost_array.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../adapted.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="boost_tuple.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 129</div> 130</body> 131</html> 132