Imported Upstream version 1.51.0
[platform/upstream/boost.git] / doc / html / boost / proto / protect.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Struct template protect</title>
5 <link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
8 <link rel="up" href="../../proto/reference.html#header.boost.proto.transform.make_hpp" title="Header &lt;boost/proto/transform/make.hpp&gt;">
9 <link rel="prev" href="noinvoke.html" title="Struct template noinvoke">
10 <link rel="next" href="protect/impl.html" title="Struct template impl">
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="noinvoke.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../proto/reference.html#header.boost.proto.transform.make_hpp"><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="protect/impl.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="refentry">
26 <a name="boost.proto.protect"></a><div class="titlepage"></div>
27 <div class="refnamediv">
28 <h2><span class="refentrytitle">Struct template protect</span></h2>
29 <p>boost::proto::protect &#8212; A <a class="link" href="../../PrimitiveTransform.html" title="Concept PrimitiveTransform">PrimitiveTransform</a> which prevents another
30           <a class="link" href="../../PrimitiveTransform.html" title="Concept PrimitiveTransform">PrimitiveTransform</a> from being applied in an
31           <a class="link" href="../../ObjectTransform.html" title="Concept ObjectTransform">ObjectTransform</a>.</p>
32 </div>
33 <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
34 <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../proto/reference.html#header.boost.proto.transform.make_hpp" title="Header &lt;boost/proto/transform/make.hpp&gt;">boost/proto/transform/make.hpp</a>&gt;
35
36 </span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <a class="link" href="../../PrimitiveTransform.html" title="Concept PrimitiveTransform">PrimitiveTransform</a><span class="special">&gt;</span> 
37 <span class="keyword">struct</span> <a class="link" href="protect.html" title="Struct template protect">protect</a> <span class="special">:</span> <span class="keyword"></span> <a class="link" href="transform.html" title="Struct template transform">proto::transform</a><span class="special">&lt;</span> <span class="identifier">protect</span><span class="special">&lt;</span><span class="identifier">PrimitiveTransform</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">{</span>
38   <span class="comment">// member classes/structs/unions</span>
39   <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="special">,</span> <span class="keyword">typename</span> <span class="special">,</span> <span class="keyword">typename</span> <span class="special">&gt;</span> 
40   <span class="keyword">struct</span> <a class="link" href="protect/impl.html" title="Struct template impl">impl</a> <span class="special">{</span>
41     <span class="comment">// types</span>
42     <span class="keyword">typedef</span> <span class="identifier">PrimitiveTransform</span> <a class="link" href="protect/impl.html#boost.proto.protect.impl.result_type"><span class="identifier">result_type</span></a><span class="special">;</span>
43   <span class="special">}</span><span class="special">;</span>
44 <span class="special">}</span><span class="special">;</span></pre></div>
45 <div class="refsect1">
46 <a name="id2930333"></a><h2>Description</h2>
47 <p>
48             When building higher order transforms with
49             <code class="computeroutput">
50               <a class="link" href="make.html" title="Struct template make">proto::make&lt;&gt;</a>
51             </code> or
52             <code class="computeroutput">
53               <a class="link" href="lazy.html" title="Struct template lazy">proto::lazy&lt;&gt;</a>
54             </code>,
55             you sometimes would like to build types that are parameterized with Proto transforms. In such
56             lambda-style transforms, Proto will unhelpfully find all nested transforms and apply them, even
57             if you don't want them to be applied. Consider the following transform, which will replace the
58             <code class="computeroutput">proto::_</code> in
59             <code class="computeroutput">Bar&lt;proto::_&gt;()</code>
60             with <code class="computeroutput">proto::terminal&lt;int&gt;::type</code>:
61           </p>
62 <p>
63             </p>
64 <pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
65 <span class="keyword">struct</span> <span class="identifier">Bar</span>
66 <span class="special">{</span><span class="special">}</span><span class="special">;</span>
67
68 <span class="keyword">struct</span> <span class="identifier">Foo</span> <span class="special">:</span>
69   <a class="link" href="when.html" title="Struct template when">proto::when</a><span class="special">&lt;</span><a class="link" href="_.html" title="Struct _">proto::_</a><span class="special">,</span> <span class="identifier">Bar</span><span class="special">&lt;</span><a class="link" href="_.html" title="Struct _">proto::_</a><span class="special">&gt;</span><span class="special">(</span><span class="special">)</span> <span class="special">&gt;</span>
70 <span class="special">{</span><span class="special">}</span><span class="special">;</span>
71
72 <a class="link" href="terminal.html" title="Struct template terminal">proto::terminal</a><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span><span class="special">::</span><span class="identifier">type</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">{</span><span class="number">0</span><span class="special">}</span><span class="special">;</span>
73
74 <span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="special">)</span> <span class="special">{</span>
75   <span class="identifier">Foo</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="identifier">i</span><span class="special">)</span><span class="special">;</span>
76   <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="keyword">typeid</span><span class="special">(</span><span class="identifier">Foo</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="identifier">i</span><span class="special">)</span><span class="special">)</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
77 <span class="special">}</span></pre>
78 <p>
79           </p>
80 <p>
81             If you actually wanted to default-construct an object of type
82             <code class="computeroutput">Bar&lt;proto::_&gt;</code>, you would have to protect the
83             <code class="computeroutput">_</code> to prevent it from being applied. You can
84             use <code class="computeroutput">proto::protect&lt;&gt;</code> as follows:
85           </p>
86 <p>
87             </p>
88 <pre class="programlisting"><span class="comment">// OK: replace anything with Bar&lt;_&gt;()</span>
89 <span class="keyword">struct</span> <span class="identifier">Foo</span> <span class="special">:</span>
90   <a class="link" href="when.html" title="Struct template when">proto::when</a><span class="special">&lt;</span><a class="link" href="_.html" title="Struct _">proto::_</a><span class="special">,</span> <span class="identifier">Bar</span><span class="special">&lt;</span><a class="link" href="protect.html" title="Struct template protect">proto::protect</a><span class="special">&lt;</span><a class="link" href="_.html" title="Struct _">proto::_</a><span class="special">&gt;</span> <span class="special">&gt;</span><span class="special">(</span><span class="special">)</span> <span class="special">&gt;</span>
91 <span class="special">{</span><span class="special">}</span><span class="special">;</span></pre>
92 <p>
93           </p>
94 </div>
95 </div>
96 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
97 <td align="left"></td>
98 <td align="right"><div class="copyright-footer">Copyright &#169; 2008 Eric Niebler<p>
99         Distributed under the Boost Software License, Version 1.0. (See accompanying
100         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>)
101       </p>
102 </div></td>
103 </tr></table>
104 <hr>
105 <div class="spirit-nav">
106 <a accesskey="p" href="noinvoke.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../proto/reference.html#header.boost.proto.transform.make_hpp"><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="protect/impl.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
107 </div>
108 </body>
109 </html>