File: vmd_modifiers_identifier.qbk

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (149 lines) | stat: -rw-r--r-- 6,954 bytes parent folder | download | duplicates (6)
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
[/ 
  (C) Copyright Edward Diener 2011-2015
  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE_1_0.txt or copy at
  http://www.boost.org/LICENSE_1_0.txt).
]

[section:vmd_modifiers_identifier Identifier modifiers]

Identifier modifiers are optional parameters which 
specify a set of identifiers to search in order to look 
for a particular identifier match rather than just any
identifier.

[heading:imid Usage with BOOST_VMD_IS_IDENTIFIER]

Once we have both registered and pre-detected an identifier we can test whether 
an identifier is a particular identifier using BOOST_VMD_IS_IDENTIFER and
identifier modifiers. We do this by passing optional parameter(s) to 
BOOST_VMD_IS_IDENTIFER. The optional parameter(s) are either a single tuple of 
possible identifiers we are trying to match, or the individual identifiers 
themselves as separate parameters.

Using the optional parameter(s) with BOOST_VMD_IS_IDENTIFER we are asking 
not only if our input is any of the registered identifiers but also if it is one
of a number of pre-detected identifiers.

As an example:

 #include <boost/vmd/is_identifier.hpp>
 
 #define BOOST_VMD_REGISTER_yellow (yellow)
 #define BOOST_VMD_REGISTER_green (green)
 #define BOOST_VMD_REGISTER_blue (blue)
 #define BOOST_VMD_REGISTER_red (red)
 
 #define BOOST_VMD_DETECT_yellow_yellow
 #define BOOST_VMD_DETECT_green_green
 #define BOOST_VMD_DETECT_blue_blue
 
 BOOST_VMD_IS_IDENTIFIER(some_input,yellow) // returns 1 only if 'some_input is 'yellow', else returns 0
 BOOST_VMD_IS_IDENTIFIER(some_input,yellow,blue) // returns 1 only if 'some_input is 'yellow' or 'blue', else returns 0
 BOOST_VMD_IS_IDENTIFIER(some_input,(yellow,green)) // returns 1 if 'some_input' is 'yellow' or 'green', else returns 0
 
 BOOST_VMD_IS_IDENTIFIER(some_input,red) 
    // always returns 0, even if 'some_input' is 'red' since 'red' has not been pre-detected

whereas
 
 BOOST_VMD_IS_IDENTIFIER(some_input) // returns 1 if 'some_input' is 'red' since 'red' has been registered
 
If you invoke BOOST_VMD_IS_IDENTIFIER with the optional parameter(s), the invocation will
only return 1 if the input matches one the identifier(s) of the optional parameters and the 
identifier it matches has been registered and pre-detected.

Both VMD numbers and v-types are identifier subtypes so you can also use them
as identifier modifiers. You do not have to register or pre-detect VMD numbers
or v-types since VMD has already done that for you.

As an example of using VMD numbers or v-types as identifier modifiers with BOOST_VMD_IS_IDENTIFIER:

 BOOST_VMD_IS_IDENTIFIER(some_input,1,3,5) // returns 1 only if 'some_input' is 1 or 3 or 5, else returns 0
 BOOST_VMD_IS_IDENTIFIER(some_input,BOOST_VMD_TYPE_TUPLE,BOOST_VMD_TYPE_LIST,59) 
    // returns 1 only if 'some_input is the v-type BOOST_VMD_TYPE_TUPLE or the v-type BOOST_VMD_TYPE_LIST or 59, else returns 0


[heading Usage with BOOST_VMD_ELEM]

When we use the specific filter modifier BOOST_VMD_TYPE_IDENTIFIER as an optional
parameter of BOOST_VMD_ELEM we are asking for a particular element of a sequence
as long as it is a VMD identifier. With that specific filter modifier 
BOOST_VMD_TYPE_IDENTIFIER we can use identifier modifiers to ask for a particular 
element of a sequence as long as it matches one of our identifier modifiers. If
the specific filter modifier BOOST_VMD_TYPE_IDENTIFIER is not being used then all 
identifier modifiers are ignored.

The syntax for specifying identifier modifiers using BOOST_VMD_ELEM is 
exactly the same as the equivalent feature of the BOOST_VMD_IS_IDENTIFIER 
macro explained just previously. Optional parameters in the form of 
identifiers can be specified either singly any number of times or once 
as part of a tuple. For an identifier found as a sequence element to 
match against one of these possible identifiers, the possible 
identifiers must be both registered and pre-detected.

Since filter modifiers, which are v-types, are also identifiers, if
you want to use v-types as identifier modifiers you must use the form
which places all identifier modifiers as part of a tuple. Otherwise any
v-types specified singly as optional parameters are seen as filter
modifiers and never as identifier modifiers. VMD numbers are also identifiers
and may be used as identifier modifiers, but in this case VMD numbers as
identifier modifiers do not need to be part of a tuple to be detected.

Let's see how this works:

 #include <boost/vmd/elem.hpp>
 
 #define BOOST_VMD_REGISTER_ANAME (ANAME)
 #define BOOST_VMD_REGISTER_APLACE (APLACE)
 #define BOOST_VMD_REGISTER_ACOUNTRY (ACOUNTRY)
 
 #define BOOST_VMD_DETECT_ANAME_ANAME
 #define BOOST_VMD_DETECT_APLACE_APLACE
 
 #define A_SEQUENCE (1,2,3) ANAME 46 BOOST_VMD_TYPE_SEQ ACOUNTRY

 BOOST_VMD_ELEM(1,A_SEQUENCE) will return 'ANAME'
 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER) will return 'ANAME'
 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,APLACE,ACOUNTRY) will return emptiness
 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,ANAME,APLACE,ACOUNTRY) will return 'ANAME'
 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,(APLACE,ACOUNTRY,ANAME)) will return 'ANAME'
 
 BOOST_VMD_ELEM(4,A_SEQUENCE) will return 'ACOUNTRY'
 BOOST_VMD_ELEM(4,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER) will return 'ACOUNTRY'
 BOOST_VMD_ELEM(4,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,ACOUNTRY,ANAME) 
    will return emptiness since ACOUNTRY is not pre-detected
 
Let us illustrate the case where VMD identifiers can be represented as either
filter modifiers or identifier modifiers.

Using the sequence above:

 #include <boost/vmd/elem.hpp>
 
 BOOST_VMD_ELEM(3,A_SEQUENCE) will return the BOOST_VMD_TYPE_SEQ type
 BOOST_VMD_ELEM(3,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER) 
    will return the BOOST_VMD_TYPE_SEQ type since a type is an identifier
 BOOST_VMD_ELEM(3,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_TYPE_SEQ,BOOST_VMD_TYPE_TUPLE) will return emptiness
 
The last use of our macro returns emptiness because if there is more than one
type specified as an optional parameter the last type is chosen for filtering.
Since the last type for type filtering is BOOST_VMD_TYPE_TUPLE and our fourth
element is a v-type and not a tuple, emptiness is returned. The syntax does not 
specifying filtering with identifiers as might be supposed since BOOST_VMD_TYPE_SEQ
and BOOST_VMD_TYPE_TUPLE are not treated as identifier modifiers but rather as 
additional filter modifiers.

In order to do filtering with an identifier and do it against
various types themselves, since v-types are identifiers, we must
use the tuple form to specify our identifier modifiers:
 
 #include <boost/vmd/elem.hpp>
 
 BOOST_VMD_ELEM(3,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,(BOOST_VMD_TYPE_SEQ,BOOST_VMD_TYPE_TUPLE)) 
    will return BOOST_VMD_TYPE_SEQ
 
Now BOOST_VMD_TYPE_SEQ and BOOST_VMD_TYPE_TUPLE are treated as identifiers
modifiers to match against.

[endsect]