• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Splitting modifiers</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. The Variadic Macro Data Library 1.9">
8<link rel="up" href="../vmd_modifiers.html" title="Macros with modifiers">
9<link rel="prev" href="vmd_modifiers_identifier.html" title="Identifier modifiers">
10<link rel="next" href="vmd_modifiers_index.html" title="Index modifiers">
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="vmd_modifiers_identifier.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../vmd_modifiers.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="vmd_modifiers_index.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="variadic_macro_data.vmd_modifiers.vmd_modifiers_splitting"></a><a class="link" href="vmd_modifiers_splitting.html" title="Splitting modifiers">Splitting
28      modifiers</a>
29</h3></div></div></div>
30<p>
31        The BOOST_VMD_ELEM macro, which by default just returns an element of a sequence,
32        has a usage where you can have it return both the element and the remaining
33        part of the sequence after the element, or even just the remaining part of
34        the sequence after the element by itself. This offers a form of splitting
35        the sequence on a particular element. When used to return the remaining part
36        of a sequence the remaining data may subsequently be treated as a VMD sequence
37        again.
38      </p>
39<p>
40        To do this another set of optional modifiers are used which will be called
41        'splitting modifers'. These modifiers are:
42      </p>
43<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
44<li class="listitem">
45            BOOST_VMD_RETURN_AFTER, which returns both the element information and
46            the rest of the sequence after the element as a two-element tuple
47          </li>
48<li class="listitem">
49            BOOST_VMD_RETURN_ONLY_AFTER, which returns only the rest of the sequence
50            after the element specified
51          </li>
52<li class="listitem">
53            BOOST_VMD_RETURN_NO_AFTER, this is the internal default which only returns
54            the element itself. It need never be specified but may be used to override
55            a previous splitting modifier specified as an optional parameter.
56          </li>
57</ul></div>
58<p>
59        If more than one of the splitting modifiers are specified as optional parameters
60        to BOOST_VMD_ELEM the last one specified is in effect.
61      </p>
62<p>
63        The splitting modifiers BOOST_VMD_RETURN_NO_AFTER and BOOST_VMD_RETURN_AFTER
64        work with either return type modifiers or filtering modifiers if they are
65        used. The splitting modifier BOOST_VMD_RETURN_ONLY_AFTER works with filtering
66        modifiers if it is used and any return type modifiers will be ignored. Optional
67        modifiers may occur in any order after the required parameters to BOOST_VMD_ELEM.
68      </p>
69<p>
70        If BOOST_VMD_RETURN_AFTER is in effect and an element is not found, either
71        because the element number is out of range for the sequence or because filtering
72        does not match the element type, a tuple will still be returned but both
73        its elements will be empty.
74      </p>
75<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">vmd</span><span class="special">/</span><span class="identifier">elem</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
76
77<span class="preprocessor">#define</span> <span class="identifier">BOOST_VMD_REGISTER_ANAME</span> <span class="special">(</span><span class="identifier">ANAME</span><span class="special">)</span> <span class="comment">// an identifier must always be registered to be found by VMD</span>
78<span class="preprocessor">#define</span> <span class="identifier">A_SEQUENCE</span> <span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">)</span> <span class="number">46</span> <span class="special">(</span><span class="identifier">list_data1</span><span class="special">,</span><span class="identifier">BOOST_PP_NIL</span><span class="special">)</span> <span class="identifier">BOOST_VMD_TYPE_SEQ</span> <span class="identifier">ANAME</span>
79
80<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="char">'(list_data1,BOOST_PP_NIL)'</span>
81<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_NO_AFTER</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="char">'(list_data1,BOOST_PP_NIL)'</span>
82<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_AFTER</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="char">'((list_data1,BOOST_PP_NIL),BOOST_VMD_TYPE_SEQ ANAME)'</span>
83<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_ONLY_AFTER</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="char">'BOOST_VMD_TYPE_SEQ ANAME'</span>
84
85<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">5</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="identifier">emptiness</span>
86<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">5</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_NO_AFTER</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="identifier">emptiness</span>
87<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">5</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_AFTER</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="char">'(,)'</span>
88<span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">5</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_ONLY_AFTER</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="identifier">emptiness</span>
89</pre>
90<p>
91        Combining splitting modifiers with return type modifiers:
92      </p>
93<pre class="programlisting"><span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_AFTER</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_TYPE</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="char">'((BOOST_VMD_TYPE_LIST,(list_data1,BOOST_PP_NIL)),BOOST_VMD_TYPE_SEQ ANAME)'</span>
94</pre>
95<p>
96        Combining splitting modifiers with filtering modifiers:
97      </p>
98<pre class="programlisting"><span class="identifier">BOOST_VMD_ELEM</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="identifier">A_SEQUENCE</span><span class="special">,</span><span class="identifier">BOOST_VMD_RETURN_AFTER</span><span class="special">,</span><span class="identifier">BOOST_VMD_TYPE_LIST</span><span class="special">)</span> <span class="identifier">will</span> <span class="keyword">return</span> <span class="char">'((list_data1,BOOST_PP_NIL),BOOST_VMD_TYPE_SEQ ANAME)'</span>
99</pre>
100</div>
101<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
102<td align="left"></td>
103<td align="right"><div class="copyright-footer">Copyright © 2010-2017 Tropic Software
104      East Inc</div></td>
105</tr></table>
106<hr>
107<div class="spirit-nav">
108<a accesskey="p" href="vmd_modifiers_identifier.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../vmd_modifiers.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="vmd_modifiers_index.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
109</div>
110</body>
111</html>
112