1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Using boost::ref</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.Numeric.Odeint"> 8<link rel="up" href="../odeint_in_detail.html" title="odeint in detail"> 9<link rel="prev" href="state_types__algebras_and_operations.html" title="State types, algebras and operations"> 10<link rel="next" href="using_boost__range.html" title="Using boost::range"> 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="../../logo.jpg"></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="state_types__algebras_and_operations.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../odeint_in_detail.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="using_boost__range.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_numeric_odeint.odeint_in_detail.using_boost__ref"></a><a class="link" href="using_boost__ref.html" title="Using boost::ref">Using 28 boost::ref</a> 29</h3></div></div></div> 30<p> 31 In odeint all system functions and observers are passed by value. For example, 32 if you call a <code class="computeroutput"><span class="identifier">do_step</span></code> method 33 of a particular stepper or the integration functions, your system and your 34 stepper will be passed by value: 35 </p> 36<p> 37</p> 38<pre class="programlisting"><span class="identifier">rk4</span><span class="special">.</span><span class="identifier">do_step</span><span class="special">(</span> <span class="identifier">sys</span> <span class="special">,</span> <span class="identifier">x</span> <span class="special">,</span> <span class="identifier">t</span> <span class="special">,</span> <span class="identifier">dt</span> <span class="special">);</span> <span class="comment">// pass sys by value</span> 39</pre> 40<p> 41 </p> 42<p> 43 This behavior is suitable for most systems, especially if your system does 44 not contain any data or only a few parameters. However, in some cases you 45 might contain some large amount of data with you system function and passing 46 them by value is not desired since the data would be copied. 47 </p> 48<p> 49 In such cases you can easily use <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span></code> (and 50 its relative <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">cref</span></code>) which passes its argument by reference 51 (or constant reference). odeint will unpack the arguments and no copying 52 at all of your system object will take place: 53 </p> 54<p> 55</p> 56<pre class="programlisting"><span class="identifier">rk4</span><span class="special">.</span><span class="identifier">do_step</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">sys</span> <span class="special">)</span> <span class="special">,</span> <span class="identifier">x</span> <span class="special">,</span> <span class="identifier">t</span> <span class="special">,</span> <span class="identifier">dt</span> <span class="special">);</span> <span class="comment">// pass sys as references</span> 57</pre> 58<p> 59 </p> 60<p> 61 The same mechanism can be used for the observers in the integrate functions. 62 </p> 63<div class="tip"><table border="0" summary="Tip"> 64<tr> 65<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/src/images/tip.png"></td> 66<th align="left">Tip</th> 67</tr> 68<tr><td align="left" valign="top"><p> 69 If you are using C++11 you can also use <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ref</span></code> 70 and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cref</span></code> 71 </p></td></tr> 72</table></div> 73</div> 74<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 75<td align="left"></td> 76<td align="right"><div class="copyright-footer">Copyright © 2009-2015 Karsten Ahnert and Mario Mulansky<p> 77 Distributed under the Boost Software License, Version 1.0. (See accompanying 78 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>) 79 </p> 80</div></td> 81</tr></table> 82<hr> 83<div class="spirit-nav"> 84<a accesskey="p" href="state_types__algebras_and_operations.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../odeint_in_detail.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="using_boost__range.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 85</div> 86</body> 87</html> 88