File: examples_preprocessed.htm

package info (click to toggle)
boost 1.27.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,908 kB
  • ctags: 26,546
  • sloc: cpp: 122,225; ansic: 10,956; python: 4,412; sh: 855; yacc: 803; makefile: 257; perl: 165; lex: 90; csh: 6
file content (343 lines) | stat: -rw-r--r-- 7,499 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Boost.Preprocessor - Tutorial examples preprocessed</title>
</head>
<body bgcolor="#FFFFFF" link="#0000ff" vlink="#800080">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
    "header">
  <tr> 
    <td valign="top" width="300"> 
      <h3><a href="../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../c++boost.gif" border="0"></a></h3>
    </td>
    <td valign="top"> 
      <h1 align="center">Boost.Preprocessor</h1>
      <h2 align="center">Tutorial examples preprocessed</h2>
    </td>
  </tr>
</table>
<hr>

<p>The following code snippets were produced by actually preprocessing the code 
  snippets of the tutorial. After preprocessing the code was reformatted manually.</p>

<hr>
<p><strong><a name="Local Macro"></a><a href="tutorial.htm#Local Macro">EXAMPLE</a>:</strong> 
  Use a Local Macro to avoid small scale repetition</p>

<blockquote>
  <pre>template&lt;class T, int n&gt;
vec&lt;T,n&gt;&
  operator +=
  ( vec&lt;T,n&gt;&
      lhs
  , const vec&lt;T,n&gt;&
      rhs
  )
{ for (int i=0; i&lt;n; ++i)
    lhs(i) += rhs(i);
  return lhs;
}

template&lt;class T, int n&gt;
vec&lt;T,n&gt;&
  operator -=
  ( vec&lt;T,n&gt;&
      lhs
  , const vec&lt;T,n&gt;&
      rhs
  )
{ for (int i=0; i&lt;n; ++i)
    lhs(i) -= rhs(i);
  return lhs;
}

template&lt;class T, int n&gt;
vec&lt;T,n&gt;&
  operator *=
  ( vec&lt;T,n&gt;&
      lhs
  , const vec&lt;T,n&gt;&
      rhs
  )
{ for (int i=0; i&lt;n; ++i)
    lhs(i) *= rhs(i);
  return lhs;
}

template&lt;class T, int n&gt;
vec&lt;T,n&gt;&
  operator /=
  ( vec&lt;T,n&gt;&
      lhs
  , const vec&lt;T,n&gt;&
      rhs
  )
{ for (int i=0; i&lt;n; ++i)
    lhs(i) /= rhs(i);
  return lhs;
}
</pre>
</blockquote>

<hr>
<p><strong><a name="UNUSED"></a><a href="tutorial.htm#UNUSED">EXAMPLE</a>:</strong> 
  Use BOOST_PP_EMPTY() as an unused parameter in Local Macro instantiations</p>

<blockquote>
  <pre>template&lt;class base&gt;
typename implement_subscript_using_begin_subscript&lt;base&gt;::value_type&
  implement_subscript_using_begin_subscript&lt;base&gt;::operator[]
  ( index_type
      i
  )
{ return base::begin()[i];
}

template&lt;class base&gt;
const typename implement_subscript_using_begin_subscript&lt;base&gt;::value_type&
  implement_subscript_using_begin_subscript&lt;base&gt;::operator[]
  ( index_type
      i
  ) const
{ return base::begin()[i];
}
</pre>
</blockquote>

<hr>
<p><b><a name="CAT"></a><a href="tutorial.htm#CAT">EXAMPLE:</a></b> Use BOOST_PP_CAT instead of ## when necessary</p>

<blockquote>
  <pre>enum
{ static_check_152 = (sizeof(int) &lt;= sizeof(long)) ? 1 : -1
};
typedef char
  static_assert_152
  [ static_check_152
  ];
</pre>
</blockquote>
<hr>
<p><b><a name="STRINGIZE"></a><a href="tutorial.htm#STRINGIZE">EXAMPLE:</a></b> Use BOOST_PP_STRINGIZE instead of # whenever necessary</p>
<blockquote>
  <pre>#pragma message("examples.cpp" "(" "20" ") : " "TBD!")</pre>
</blockquote>
<hr>
<p><strong><a name="ENUM_PARAMS"></a><a href="tutorial.htm#ENUM_PARAMS">EXAMPLE</a>:</strong> 
  Use:</p>
<ul>
  <li> BOOST_PP_ENUM_PARAMS,</li>
  <li> BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT,</li>
  <li> BOOST_PP_ENUM_PARAMS_WITH_DEFAULTS,</li>
  <li> BOOST_PP_ENUM_SHIFTED_PARAMS, or</li>
  <li>BOOST_PP_REPEAT, and</li>
  <li> BOOST_PP_COMMA_IF</li>
</ul>
<p>to avoid O(N) repetition on lists in general</p>
<blockquote>
  <pre>struct make_type_list_end;

template
&lt; class T0=make_type_list_end
, class T1=make_type_list_end
, class T2=make_type_list_end
, class T3=make_type_list_end
, class T4=make_type_list_end
, class T5=make_type_list_end
, class T6=make_type_list_end
, class T7=make_type_list_end
&gt;
struct make_type_list
{
private:
  enum
  { end = is_same&lt;T0,make_type_list_end&gt;::value
  };
public:
  typedef typename
    type_if
    &lt; end
    , type_cons_empty
    , type_cons
      &lt; T0
      , typename
        type_inner_if
        &lt; end
        , type_identity&lt;end&gt;
        , make_type_list
          &lt; T1
          , T2
          , T3
          , T4
          , T5
          , T6
          , T7
          &gt;
        &gt;::type
      &gt;
    &gt;::type type;
};
</pre>
</blockquote>

<hr>
<p><strong><a name="Token Look-Up"></a><a href="tutorial.htm#Token Look-Up">EXAMPLE</a>:</strong> 
  Use BOOST_PP_REPEAT and a Token Look-Up Function to eliminate categorical 
  repetition</p>

<blockquote>
  <pre>catch (bool t)
{ report_typeid(t);
  report_value(t);
}
catch (char t)
{ report_typeid(t);
  report_value(t);
}
catch (signed char t)
{ report_typeid(t);
  report_value(t);
}
catch (unsigned char t)
{ report_typeid(t);
  report_value(t);
}
catch (short t)
{ report_typeid(t);
  report_value(t);
}
catch (unsigned short t)
{ report_typeid(t);
  report_value(t);
}
catch (int t)
{ report_typeid(t);
  report_value(t);
}
catch (unsigned int t)
{ report_typeid(t);
  report_value(t);
}
catch (long t)
{ report_typeid(t);
  report_value(t);
}
catch (unsigned long t)
{ report_typeid(t);
  report_value(t);
}
catch (float t)
{ report_typeid(t);
  report_value(t);
}
catch (double t)
{ report_typeid(t);
  report_value(t);
}
catch (long double t)
{ report_typeid(t);
  report_value(t);
}
</pre>
</blockquote>

<hr>
<p><strong><a name="2ND_REPEAT"></a><a href="tutorial.htm#2ND_REPEAT">EXAMPLE</a>:</strong> 
  Use BOOST_PP_REPEAT_2ND to avoid O(N*N) repetition</p>

<blockquote>
  <pre>vec()
{
}
vec(T a0)
{ (*this)[0] = a0;
}
vec(T a0, T a1)
{ (*this)[0] = a0;
  (*this)[1] = a1;
}
vec(T a0, T a1, T a2)
{ (*this)[0] = a0;
  (*this)[1] = a1;
  (*this)[2] = a2;
}
vec(T a0, T a1, T a2, T a3)
{ (*this)[0] = a0;
  (*this)[1] = a1;
  (*this)[2] = a2;
  (*this)[3] = a3;
}
vec(T a0, T a1, T a2, T a3, T a4)
{ (*this)[0] = a0;
  (*this)[1] = a1;
  (*this)[2] = a2;
  (*this)[3] = a3;
  (*this)[4] = a4;
}
vec(T a0, T a1, T a2, T a3, T a4, T a5)
{ (*this)[0] = a0;
  (*this)[1] = a1;
  (*this)[2] = a2;
  (*this)[3] = a3;
  (*this)[4] = a4;
  (*this)[5] = a5;
}
vec(T a0, T a1, T a2, T a3, T a4, T a5, T a6)
{ (*this)[0] = a0;
  (*this)[1] = a1;
  (*this)[2] = a2;
  (*this)[3] = a3;
  (*this)[4] = a4;
  (*this)[5] = a5;
  (*this)[6] = a6;
}
vec(T a0, T a1, T a2, T a3, T a4, T a5, T a6, T a7)
{ (*this)[0] = a0;
  (*this)[1] = a1;
  (*this)[2] = a2;
  (*this)[3] = a3;
  (*this)[4] = a4;
  (*this)[5] = a5;
  (*this)[6] = a6;
  (*this)[7] = a7;
}
</pre>
</blockquote>

<p> 
<hr>
<p><a name="IF"></a><a href="tutorial.htm#IF"><b>EXAMPLE:</b></a> 
  Use BOOST_PP_IF to implement special case for the first element</p>

<blockquote> 
  <pre>false == false;
true == true;
</pre>
</blockquote>

<p> 
<hr>

<p><a name="Arithmetic"></a><a href="tutorial.htm#Arithmetic"><B>EXAMPLE:</B></a> Use arithmetic, logical and comparison operations when necessary</p>

<blockquote> 
  <pre>S, E0, E1
E0, S, E1
E0, E1, S
BAD PARAMS FOR SPECIAL_NUMBERED_LIST! E0, E1, E2, S</pre>
</blockquote>

<hr>
<p>Revised 
  <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
  <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href="http://www.housemarque.com">Housemarque Oy</a> 2002</i></p>

<p><i>Permission to copy, use, modify, sell and distribute this document is granted
provided this copyright notice appears in all copies. This document is provided
"as is" without express or implied warranty, and with no claim as to its suitability
for any purpose.</i></p>
</body>
</html>