1 <?xml version=
"1.0" encoding=
"utf-8"?>
3 Copyright 2012 Eric Niebler
5 Distributed under the Boost
6 Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 <header name=
"boost/proto/repeat.hpp">
11 Contains macros to ease the generation of repetitious code constructs.
14 <macro name=
"BOOST_PROTO_REPEAT" kind=
"functionlike">
15 <macro-parameter name=
"MACRO"/>
16 <purpose>Repeatedly invoke the specified macro.
</purpose>
19 <computeroutput>BOOST_PROTO_REPEAT()
</computeroutput> is used to generate the kind of repetitive
20 code that is typical of EDSLs built with Proto.
21 <computeroutput>BOOST_PROTO_REPEAT(
<replaceable>MACRO
</replaceable>)
</computeroutput>
25 <programlisting><replaceable>MACRO
</replaceable>(
1,
<macroname>BOOST_PROTO_typename_A
</macroname>,
<macroname>BOOST_PROTO_A_const_ref
</macroname>,
<macroname>BOOST_PROTO_A_const_ref_a
</macroname>,
<macroname>BOOST_PROTO_ref_a
</macroname>)
26 <replaceable>MACRO
</replaceable>(
2,
<macroname>BOOST_PROTO_typename_A
</macroname>,
<macroname>BOOST_PROTO_A_const_ref
</macroname>,
<macroname>BOOST_PROTO_A_const_ref_a
</macroname>,
<macroname>BOOST_PROTO_ref_a
</macroname>)
28 <replaceable>MACRO
</replaceable>(
<macroname>BOOST_PROTO_MAX_ARITY
</macroname>,
<macroname>BOOST_PROTO_typename_A
</macroname>,
<macroname>BOOST_PROTO_A_const_ref
</macroname>,
<macroname>BOOST_PROTO_A_const_ref_a
</macroname>,
<macroname>BOOST_PROTO_ref_a
</macroname>)
</programlisting>
31 <emphasis role=
"bold">Example:
</emphasis>
34 See
<computeroutput><macroname>BOOST_PROTO_REPEAT_FROM_TO
</macroname>()
</computeroutput>.
39 <macro name=
"BOOST_PROTO_REPEAT_FROM_TO" kind=
"functionlike">
40 <macro-parameter name=
"FROM"/>
41 <macro-parameter name=
"TO"/>
42 <macro-parameter name=
"MACRO"/>
43 <purpose>Repeatedly invoke the specified macro.
</purpose>
46 <computeroutput>BOOST_PROTO_REPEAT_FROM_TO()
</computeroutput> is used to generate the kind of repetitive
47 code that is typical of EDSLs built with Proto.
48 <computeroutput>BOOST_PROTO_REPEAT_FROM_TO(
<replaceable>FROM
</replaceable>,
<replaceable>TO
</replaceable>,
<replaceable>MACRO
</replaceable>)
</computeroutput>
52 <programlisting><replaceable>MACRO
</replaceable>(
<replaceable>FROM
</replaceable>,
<macroname>BOOST_PROTO_typename_A
</macroname>,
<macroname>BOOST_PROTO_A_const_ref
</macroname>,
<macroname>BOOST_PROTO_A_const_ref_a
</macroname>,
<macroname>BOOST_PROTO_ref_a
</macroname>)
53 <replaceable>MACRO
</replaceable>(
<replaceable>FROM+
1</replaceable>,
<macroname>BOOST_PROTO_typename_A
</macroname>,
<macroname>BOOST_PROTO_A_const_ref
</macroname>,
<macroname>BOOST_PROTO_A_const_ref_a
</macroname>,
<macroname>BOOST_PROTO_ref_a
</macroname>)
55 <replaceable>MACRO
</replaceable>(
<replaceable>TO-
1</replaceable>,
<macroname>BOOST_PROTO_typename_A
</macroname>,
<macroname>BOOST_PROTO_A_const_ref
</macroname>,
<macroname>BOOST_PROTO_A_const_ref_a
</macroname>,
<macroname>BOOST_PROTO_ref_a
</macroname>)
</programlisting>
58 <emphasis role=
"bold">Example:
</emphasis>
61 <programlisting>// Generate BOOST_PROTO_MAX_ARITY-
1 overloads of the
62 // following construct() function template.
63 #define M0(N, typename_A, A_const_ref, A_const_ref_a, ref_a) \
64 template
<typename T, typename_A(N)
> \
65 typename
<classname alt=
"boost::proto::result_of::make_expr">proto::result_of::make_expr
</classname>< \
66 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname> \
67 , construct_helper
<T
> \
70 construct(A_const_ref_a(N)) \
72 return
<functionname alt=
"boost::proto::make_expr">proto::make_expr
</functionname>< \
73 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname> \
75 construct_helper
<T
>() \
79 BOOST_PROTO_REPEAT_FROM_TO(
1, BOOST_PROTO_MAX_ARITY, M0)
80 #undef M0
</programlisting>
83 The above invocation of
<computeroutput>BOOST_PROTO_REPEAT_FROM_TO()
</computeroutput>
84 will generate the following code:
87 <programlisting>template
<typename T, typename A0
>
88 typename
<classname alt=
"boost::proto::result_of::make_expr">proto::result_of::make_expr
</classname><
89 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
90 , construct_helper
<T
>
93 construct(A0 const
& a0)
95 return
<functionname alt=
"boost::proto::make_expr">proto::make_expr
</functionname><
96 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
98 construct_helper
<T
>()
103 template
<typename T, typename A0, typename A1
>
104 typename
<classname alt=
"boost::proto::result_of::make_expr">proto::result_of::make_expr
</classname><
105 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
106 , construct_helper
<T
>
110 construct(A0 const
& a0, A1 const
& a1)
112 return
<functionname alt=
"boost::proto::make_expr">proto::make_expr
</functionname><
113 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
115 construct_helper
<T
>()
121 // ... and so on, up to BOOST_PROTO_MAX_ARITY-
1 arguments ...
</programlisting>
126 <macro name=
"BOOST_PROTO_REPEAT_EX" kind=
"functionlike">
127 <macro-parameter name=
"MACRO"/>
128 <macro-parameter name=
"typename_A"/>
129 <macro-parameter name=
"A"/>
130 <macro-parameter name=
"A_a"/>
131 <macro-parameter name=
"a"/>
132 <purpose>Repeatedly invoke the specified macro.
</purpose>
135 <computeroutput>BOOST_PROTO_REPEAT_EX()
</computeroutput> is used to generate the kind of repetitive
136 code that is typical of EDSLs built with Proto.
137 <computeroutput>BOOST_PROTO_REPEAT_EX(
<replaceable>MACRO
</replaceable>,
<replaceable>typename_A
</replaceable>,
<replaceable>A
</replaceable>,
<replaceable>A_a
</replaceable>,
<replaceable>a
</replaceable>)
</computeroutput>
141 <programlisting><replaceable>MACRO
</replaceable>(
1, typename_A, A, A_a, a)
142 <replaceable>MACRO
</replaceable>(
2, typename_A, A, A_a, a)
144 <replaceable>MACRO
</replaceable>(
<macroname>BOOST_PROTO_MAX_ARITY
</macroname>, typename_A, A, A_a, a)
</programlisting>
147 <emphasis role=
"bold">Example:
</emphasis>
150 See
<computeroutput><macroname>BOOST_PROTO_REPEAT_FROM_TO
</macroname>()
</computeroutput>.
155 <macro name=
"BOOST_PROTO_REPEAT_FROM_TO_EX" kind=
"functionlike">
156 <macro-parameter name=
"FROM"/>
157 <macro-parameter name=
"TO"/>
158 <macro-parameter name=
"MACRO"/>
159 <macro-parameter name=
"typename_A"/>
160 <macro-parameter name=
"A"/>
161 <macro-parameter name=
"A_a"/>
162 <macro-parameter name=
"a"/>
163 <purpose>Repeatedly invoke the specified macro.
</purpose>
166 <computeroutput>BOOST_PROTO_REPEAT_FROM_TO_EX()
</computeroutput> is used to generate the kind of repetitive
167 code that is typical of EDSLs built with Proto.
168 <computeroutput>BOOST_PROTO_REPEAT_FROM_TO_EX(
<replaceable>FROM
</replaceable>,
<replaceable>TO
</replaceable>,
<replaceable>MACRO
</replaceable>,
<replaceable>typename_A
</replaceable>,
<replaceable>A
</replaceable>,
<replaceable>A_a
</replaceable>,
<replaceable>a
</replaceable>)
</computeroutput>
172 <programlisting><replaceable>MACRO
</replaceable>(
<replaceable>FROM
</replaceable>, typename_A, A, A_a, a)
173 <replaceable>MACRO
</replaceable>(
<replaceable>FROM+
1</replaceable>, typename_A, A, A_a, a)
175 <replaceable>MACRO
</replaceable>(
<replaceable>TO-
1</replaceable>, typename_A, A, A_a, a)
</programlisting>
178 <emphasis role=
"bold">Example:
</emphasis>
181 See
<computeroutput><macroname>BOOST_PROTO_REPEAT_FROM_TO
</macroname>()
</computeroutput>.
186 <macro name=
"BOOST_PROTO_LOCAL_ITERATE" kind=
"functionlike">
187 <purpose>Vertical repetition of a user-supplied macro.
</purpose>
190 <computeroutput>BOOST_PROTO_LOCAL_ITERATE()
</computeroutput> is used generate the kind of repetitive code that is typical
191 of EDSLs built with Proto. This macro causes the user-defined macro
<computeroutput>BOOST_PROTO_LOCAL_MACRO()
</computeroutput> to
192 be expanded with values in the range specified by
<computeroutput>BOOST_PROTO_LOCAL_LIMITS
</computeroutput>.
195 <emphasis role=
"bold">Usage:
</emphasis>
198 <programlisting>#include BOOST_PROTO_LOCAL_ITERATE()
</programlisting>
201 <emphasis role=
"bold">Example:
</emphasis>
204 <programlisting>// Generate BOOST_PROTO_MAX_ARITY-
1 overloads of the
205 // following construct() function template.
206 #define BOOST_PROTO_LOCAL_MACRO(N, typename_A, A_const_ref, A_const_ref_a, ref_a)\
207 template
<typename T, typename_A(N)
> \
208 typename
<classname alt=
"boost::proto::result_of::make_expr">proto::result_of::make_expr
</classname>< \
209 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname> \
210 , construct_helper
<T
> \
213 construct(A_const_ref_a(N)) \
215 return
<functionname alt=
"boost::proto::make_expr">proto::make_expr
</functionname>< \
216 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname> \
218 construct_helper
<T
>() \
222 #define BOOST_PROTO_LOCAL_LIMITS (
1, BOOST_PP_DEC(BOOST_PROTO_MAX_ARITY))
223 #include BOOST_PROTO_LOCAL_ITERATE()
</programlisting>
226 The above inclusion of
<computeroutput>BOOST_PROTO_LOCAL_ITERATE()
</computeroutput>
227 will generate the following code:
230 <programlisting>template
<typename T, typename A0
>
231 typename
<classname alt=
"boost::proto::result_of::make_expr">proto::result_of::make_expr
</classname><
232 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
233 , construct_helper
<T
>
236 construct(A0 const
& a0)
238 return
<functionname alt=
"boost::proto::make_expr">proto::make_expr
</functionname><
239 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
241 construct_helper
<T
>()
246 template
<typename T, typename A0, typename A1
>
247 typename
<classname alt=
"boost::proto::result_of::make_expr">proto::result_of::make_expr
</classname><
248 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
249 , construct_helper
<T
>
253 construct(A0 const
& a0, A1 const
& a1)
255 return
<functionname alt=
"boost::proto::make_expr">proto::make_expr
</functionname><
256 <classname alt=
"boost::proto::tag::function">proto::tag::function
</classname>
258 construct_helper
<T
>()
264 // ... and so on, up to BOOST_PROTO_MAX_ARITY-
1 arguments ...
</programlisting>
267 If
<computeroutput>BOOST_PROTO_LOCAL_LIMITS
</computeroutput> is not defined by the user, it defaults
268 to
<computeroutput>(
1, BOOST_PROTO_MAX_ARITY)
</computeroutput>.
271 At each iteration,
<computeroutput>BOOST_PROTO_LOCAL_MACRO()
</computeroutput> is invoked with the current
272 iteration number and the following
4 macro parameters:
274 <listitem><computeroutput>BOOST_PROTO_LOCAL_typename_A
</computeroutput></listitem>
275 <listitem><computeroutput>BOOST_PROTO_LOCAL_A
</computeroutput></listitem>
276 <listitem><computeroutput>BOOST_PROTO_LOCAL_A_a
</computeroutput></listitem>
277 <listitem><computeroutput>BOOST_PROTO_LOCAL_a
</computeroutput></listitem>
279 If these macros are not defined by the user, they default respectively to:
281 <listitem><computeroutput><macroname>BOOST_PROTO_typename_A
</macroname></computeroutput></listitem>
282 <listitem><computeroutput><macroname>BOOST_PROTO_A_const_ref
</macroname></computeroutput></listitem>
283 <listitem><computeroutput><macroname>BOOST_PROTO_A_const_ref_a
</macroname></computeroutput></listitem>
284 <listitem><computeroutput><macroname>BOOST_PROTO_ref_a
</macroname></computeroutput></listitem>
288 After including
<computeroutput>BOOST_PROTO_LOCAL_ITERATE()
</computeroutput>, the
289 following macros are automatically undefined:
291 <listitem><computeroutput>BOOST_PROTO_LOCAL_MACRO
</computeroutput></listitem>
292 <listitem><computeroutput>BOOST_PROTO_LOCAL_LIMITS
</computeroutput></listitem>
293 <listitem><computeroutput>BOOST_PROTO_LOCAL_typename_A
</computeroutput></listitem>
294 <listitem><computeroutput>BOOST_PROTO_LOCAL_A
</computeroutput></listitem>
295 <listitem><computeroutput>BOOST_PROTO_LOCAL_A_a
</computeroutput></listitem>
296 <listitem><computeroutput>BOOST_PROTO_LOCAL_a
</computeroutput></listitem>
302 <macro name=
"BOOST_PROTO_typename_A" kind=
"functionlike">
303 <macro-parameter name=
"N"/>
305 Generates sequences like
307 typename A
<subscript>0</subscript>,
308 typename A
<subscript>1</subscript>, …
309 typename A
<subscript>N-
1</subscript>
314 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
315 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
318 <computeroutput>BOOST_PROTO_typename_A(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
321 <programlisting>typename A
<subscript>0</subscript>, typename A
<subscript>1</subscript>, … typename A
<subscript>N-
1</subscript></programlisting>
326 <macro name=
"BOOST_PROTO_A_const_ref" kind=
"functionlike">
327 <macro-parameter name=
"N"/>
329 Generates sequences like
331 A
<subscript>0</subscript> const
&,
332 A
<subscript>1</subscript> const
&, …
333 A
<subscript>N-
1</subscript> const
&
338 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
339 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
342 <computeroutput>BOOST_PROTO_A_const_ref(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
345 <programlisting>A
<subscript>0</subscript> const
&, A
<subscript>1</subscript> const
&, … A
<subscript>N-
1</subscript> const
&</programlisting>
350 <macro name=
"BOOST_PROTO_A_ref" kind=
"functionlike">
351 <macro-parameter name=
"N"/>
353 Generates sequences like
355 A
<subscript>0</subscript> &,
356 A
<subscript>1</subscript> &, …
357 A
<subscript>N-
1</subscript> &
362 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
363 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
366 <computeroutput>BOOST_PROTO_A_ref(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
369 <programlisting>A
<subscript>0</subscript> &, A
<subscript>1</subscript> &, … A
<subscript>N-
1</subscript> &</programlisting>
374 <macro name=
"BOOST_PROTO_A" kind=
"functionlike">
375 <macro-parameter name=
"N"/>
377 Generates sequences like
379 A
<subscript>0</subscript>,
380 A
<subscript>1</subscript>, …
381 A
<subscript>N-
1</subscript>
386 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
387 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
390 <computeroutput>BOOST_PROTO_A(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
393 <programlisting>A
<subscript>0</subscript>, A
<subscript>1</subscript>, … A
<subscript>N-
1</subscript></programlisting>
398 <macro name=
"BOOST_PROTO_A_const" kind=
"functionlike">
399 <macro-parameter name=
"N"/>
401 Generates sequences like
403 A
<subscript>0</subscript> const,
404 A
<subscript>1</subscript> const, …
405 A
<subscript>N-
1</subscript> const
410 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
411 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
414 <computeroutput>BOOST_PROTO_A_const(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
417 <programlisting>A
<subscript>0</subscript> const, A
<subscript>1</subscript> const, … A
<subscript>N-
1</subscript> const
</programlisting>
422 <macro name=
"BOOST_PROTO_A_const_ref_a" kind=
"functionlike">
423 <macro-parameter name=
"N"/>
425 Generates sequences like
427 A
<subscript>0</subscript> const
& a
<subscript>0</subscript>,
428 A
<subscript>1</subscript> const
& a
<subscript>1</subscript>, …
429 A
<subscript>N-
1</subscript> const
& a
<subscript>N-
1</subscript>
434 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
435 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
438 <computeroutput>BOOST_PROTO_A_const_ref_a(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
441 <programlisting>A
<subscript>0</subscript> const
& a
<subscript>0</subscript>, A
<subscript>1</subscript> const
& a
<subscript>1</subscript>, … A
<subscript>N-
1</subscript> const
& a
<subscript>N-
1</subscript></programlisting>
446 <macro name=
"BOOST_PROTO_A_ref_a" kind=
"functionlike">
447 <macro-parameter name=
"N"/>
449 Generates sequences like
451 A
<subscript>0</subscript> & a
<subscript>0</subscript>,
452 A
<subscript>1</subscript> & a
<subscript>1</subscript>, …
453 A
<subscript>N-
1</subscript> & a
<subscript>N-
1</subscript>
458 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
459 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
462 <computeroutput>BOOST_PROTO_A_ref_a(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
465 <programlisting>A
<subscript>0</subscript> & a
<subscript>0</subscript>, A
<subscript>1</subscript> & a
<subscript>1</subscript>, … A
<subscript>N-
1</subscript> & a
<subscript>N-
1</subscript></programlisting>
470 <macro name=
"BOOST_PROTO_ref_a" kind=
"functionlike">
471 <macro-parameter name=
"N"/>
473 Generates sequences like
475 boost::ref(a
<subscript>0</subscript>),
476 boost::ref(a
<subscript>1</subscript>), …
477 boost::ref(a
<subscript>N-
1</subscript>)
482 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
483 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
486 <computeroutput>BOOST_PROTO_ref_a(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
489 <programlisting>boost::ref(a
<subscript>0</subscript>), boost::ref(a
<subscript>1</subscript>), … boost::ref(a
<subscript>N-
1</subscript>)
</programlisting>
494 <macro name=
"BOOST_PROTO_a" kind=
"functionlike">
495 <macro-parameter name=
"N"/>
497 Generates sequences like
499 a
<subscript>0</subscript>,
500 a
<subscript>1</subscript>, …
501 a
<subscript>N-
1</subscript>
506 Intended for use with the
<computeroutput><macroname>BOOST_PROTO_REPEAT
</macroname>()
</computeroutput>
507 and
<computeroutput><macroname>BOOST_PROTO_LOCAL_ITERATE
</macroname>()
</computeroutput> macros.
510 <computeroutput>BOOST_PROTO_a(
<replaceable>N
</replaceable>)
</computeroutput> generates sequences like:
513 <programlisting>a
<subscript>0</subscript>, a
<subscript>1</subscript>, … a
<subscript>N-
1</subscript></programlisting>