1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>for_each</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. Range 2.0"> 8<link rel="up" href="../non_mutating.html" title="Non-mutating algorithms"> 9<link rel="prev" href="equal_range.html" title="equal_range"> 10<link rel="next" href="find.html" title="find"> 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="equal_range.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../non_mutating.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="find.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<a name="range.reference.algorithms.non_mutating.for_each"></a><a class="link" href="for_each.html" title="for_each">for_each</a> 28</h5></div></div></div> 29<h6> 30<a name="range.reference.algorithms.non_mutating.for_each.h0"></a> 31 <span class="phrase"><a name="range.reference.algorithms.non_mutating.for_each.prototype"></a></span><a class="link" href="for_each.html#range.reference.algorithms.non_mutating.for_each.prototype">Prototype</a> 32 </h6> 33<p> 34</p> 35<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> 36 <span class="keyword">class</span> <span class="identifier">SinglePassRange</span><span class="special">,</span> 37 <span class="keyword">class</span> <span class="identifier">UnaryFunction</span> 38 <span class="special">></span> 39<span class="identifier">UnaryFunction</span> <span class="identifier">for_each</span><span class="special">(</span><span class="identifier">SinglePassRange</span><span class="special">&</span> <span class="identifier">rng</span><span class="special">,</span> <span class="identifier">UnaryFunction</span> <span class="identifier">fun</span><span class="special">);</span> 40 41<span class="keyword">template</span><span class="special"><</span> 42 <span class="keyword">class</span> <span class="identifier">SinglePassRange</span><span class="special">,</span> 43 <span class="keyword">class</span> <span class="identifier">UnaryFunction</span> 44 <span class="special">></span> 45<span class="identifier">UnaryFunction</span> <span class="identifier">for_each</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">SinglePassRange</span><span class="special">&</span> <span class="identifier">rng</span><span class="special">,</span> <span class="identifier">UnaryFunction</span> <span class="identifier">fun</span><span class="special">);</span> 46</pre> 47<p> 48 </p> 49<h6> 50<a name="range.reference.algorithms.non_mutating.for_each.h1"></a> 51 <span class="phrase"><a name="range.reference.algorithms.non_mutating.for_each.description"></a></span><a class="link" href="for_each.html#range.reference.algorithms.non_mutating.for_each.description">Description</a> 52 </h6> 53<p> 54 <code class="computeroutput"><span class="identifier">for_each</span></code> traverses forward 55 through <code class="computeroutput"><span class="identifier">rng</span></code> and for each 56 element <code class="computeroutput"><span class="identifier">x</span></code> it invokes 57 <code class="computeroutput"><span class="identifier">fun</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code>. 58 </p> 59<h6> 60<a name="range.reference.algorithms.non_mutating.for_each.h2"></a> 61 <span class="phrase"><a name="range.reference.algorithms.non_mutating.for_each.definition"></a></span><a class="link" href="for_each.html#range.reference.algorithms.non_mutating.for_each.definition">Definition</a> 62 </h6> 63<p> 64 Defined in the header file <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">algorithm</span><span class="special">/</span><span class="identifier">for_each</span><span class="special">.</span><span class="identifier">hpp</span></code> 65 </p> 66<h6> 67<a name="range.reference.algorithms.non_mutating.for_each.h3"></a> 68 <span class="phrase"><a name="range.reference.algorithms.non_mutating.for_each.requirements"></a></span><a class="link" href="for_each.html#range.reference.algorithms.non_mutating.for_each.requirements">Requirements</a> 69 </h6> 70<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 71<li class="listitem"> 72 <code class="computeroutput"><span class="identifier">SinglePassRange</span></code> is 73 a model of the <a class="link" href="../../../concepts/single_pass_range.html" title="Single Pass Range">Single 74 Pass Range</a> Concept. 75 </li> 76<li class="listitem"> 77 <code class="computeroutput"><span class="identifier">UnaryFunction</span></code> is 78 a model of the <code class="computeroutput"><span class="identifier">UnaryFunctionConcept</span></code>. 79 </li> 80<li class="listitem"> 81 <code class="computeroutput"><span class="identifier">UnaryFunction</span></code> does 82 not apply any non-constant operation through its argument. 83 </li> 84<li class="listitem"> 85 <code class="computeroutput"><span class="identifier">SinglePassRange</span></code>'s 86 value type is convertible to <code class="computeroutput"><span class="identifier">UnaryFunction</span></code>'s 87 argument type. 88 </li> 89</ul></div> 90<h6> 91<a name="range.reference.algorithms.non_mutating.for_each.h4"></a> 92 <span class="phrase"><a name="range.reference.algorithms.non_mutating.for_each.complexity"></a></span><a class="link" href="for_each.html#range.reference.algorithms.non_mutating.for_each.complexity">Complexity</a> 93 </h6> 94<p> 95 Linear. Exactly <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)</span></code> applications of <code class="computeroutput"><span class="identifier">UnaryFunction</span></code>. 96 </p> 97</div> 98<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 99<td align="left"></td> 100<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen, 101 Neil Groves<p> 102 Distributed under the Boost Software License, Version 1.0. (See accompanying 103 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>) 104 </p> 105</div></td> 106</tr></table> 107<hr> 108<div class="spirit-nav"> 109<a accesskey="p" href="equal_range.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../non_mutating.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="find.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 110</div> 111</body> 112</html> 113