1[/ 2 (C) Copyright Edward Diener 2011-2015 3 Distributed under the Boost Software License, Version 1.0. 4 (See accompanying file LICENSE_1_0.txt or copy at 5 http://www.boost.org/LICENSE_1_0.txt). 6] 7 8[section:vmd_modifiers_index Index modifiers] 9 10Index modifiers can be used with the BOOST_VMD_ELEM macro 11when identifier modifiers are being used. Index modifiers 12take two values: 13 14* BOOST_VMD_RETURN_INDEX, return an index as a number, starting with 0, 15of the particular identifier modifier which matched, as part of the 16output of the BOOST_VMD_ELEM macro. If no particular identifier modifier 17matches, return emptiness as part of the output. The index number is 18determined purely by the order in which identifier modifiers are 19specified as optional parameters to BOOST_VMD_ELEM, whether singly as 20individual optional parameters or as a tuple of identifier modifiers. 21* BOOST_VMD_RETURN_NO_INDEX, do not return an index as part of the output. 22This is the default value and need only be used to override the 23BOOST_VMD_RETURN_INDEX value if it is specified. 24 25The BOOST_VMD_RETURN_INDEX tells the programmer which one of the identifier 26modifiers matched the element's data as an index. Some macro programmers 27find this more useful for the purposes of macro branching logic than 28branching using the actual name of the identifier itself. 29 30When the index modifier BOOST_VMD_RETURN_INDEX is specified, and identifier 31modifiers are specified along with the BOOST_VMD_TYPE_IDENTIFIER filter 32modifier, the output of BOOST_VMD_ELEM becomes a tuple of two elements. 33The first tuple element is the element matched and the last tuple element is the 34index, starting with 0, of the identifier modifier which matched. If an element 35is not matched both tuple elements are empty. 36 37If the splitting modifier BOOST_VMD_RETURN_AFTER is also specified then the 38output is a tuple of three elements. The first tuple element is the element matched, 39the second tuple element is the rest of the sequence after the matching element, 40and the last tuple element is the numeric index. If an element is not matched 41then all three tuple elements are empty. 42 43If identifier modifiers and the BOOST_VMD_TYPE_IDENTIFIER filter modifier 44are not specified as optional parameters, then if BOOST_VMD_RETURN_INDEX is 45specified it is ignored. If the splitting modifier BOOST_VMD_RETURN_ONLY_AFTER 46is specified, if BOOST_VMD_RETURN_INDEX is also specified it is ignored. 47 48Let's see how this works: 49 50 #include <boost/vmd/elem.hpp> 51 52 #define BOOST_VMD_REGISTER_ANAME (ANAME) 53 #define BOOST_VMD_REGISTER_APLACE (APLACE) 54 #define BOOST_VMD_REGISTER_ACOUNTRY (ACOUNTRY) 55 56 #define BOOST_VMD_DETECT_ANAME_ANAME 57 #define BOOST_VMD_DETECT_APLACE_APLACE 58 59 #define A_SEQUENCE (1,2,3) ANAME (1)(2) 46 60 61 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER) will return 'ANAME' 62 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,APLACE,ACOUNTRY) will return emptiness 63 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_RETURN_INDEX,APLACE,ACOUNTRY) will return (,) 64 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_RETURN_INDEX,ANAME,APLACE,ACOUNTRY) will return '(ANAME,0)' 65 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_RETURN_INDEX,(APLACE,ACOUNTRY,ANAME)) will return '(ANAME,2)' 66 67Used with splitting modifiers: 68 69 #include <boost/vmd/elem.hpp> 70 71 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_RETURN_INDEX,APLACE,ACOUNTRY,BOOST_VMD_RETURN_AFTER) will return (,,) 72 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_RETURN_INDEX,ANAME,APLACE,ACOUNTRY,BOOST_VMD_RETURN_AFTER) will return '(ANAME,(1)(2) 46,0)' 73 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_RETURN_INDEX,(APLACE,ACOUNTRY,ANAME),BOOST_VMD_RETURN_AFTER) will return '(ANAME,(1)(2) 46,2)' 74 75 BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER,BOOST_VMD_RETURN_INDEX,(APLACE,ACOUNTRY,ANAME),BOOST_VMD_RETURN_ONLY_AFTER) will return '(1)(2) 46' 76 77[endsect]