vmd_modifiers_index.qbk 3.9 KB

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