vmd_modifiers_splitting.qbk 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_splitting Splitting modifiers]
  8. The BOOST_VMD_ELEM macro, which by default just returns an element of
  9. a sequence, has a usage where you can have it return both the
  10. element and the remaining part of the sequence after the element,
  11. or even just the remaining part of the sequence after the element by itself.
  12. This offers a form of splitting the sequence on a particular element. When
  13. used to return the remaining part of a sequence the remaining data may
  14. subsequently be treated as a VMD sequence again.
  15. To do this another set of optional modifiers are used which will
  16. be called 'splitting modifers'. These modifiers are:
  17. * BOOST_VMD_RETURN_AFTER, which returns both the element information and the
  18. rest of the sequence after the element as a two-element tuple
  19. * BOOST_VMD_RETURN_ONLY_AFTER, which returns only the rest of the sequence
  20. after the element specified
  21. * BOOST_VMD_RETURN_NO_AFTER, this is the internal default which only returns
  22. the element itself. It need never be specified but may be used to override
  23. a previous splitting modifier specified as an optional parameter.
  24. If more than one of the splitting modifiers are specified as optional parameters
  25. to BOOST_VMD_ELEM the last one specified is in effect.
  26. The splitting modifiers BOOST_VMD_RETURN_NO_AFTER and BOOST_VMD_RETURN_AFTER
  27. work with either return type modifiers or filtering modifiers if they are
  28. used. The splitting modifier BOOST_VMD_RETURN_ONLY_AFTER works with
  29. filtering modifiers if it is used and any return type modifiers will be ignored.
  30. Optional modifiers may occur in any order after the required parameters
  31. to BOOST_VMD_ELEM.
  32. If BOOST_VMD_RETURN_AFTER is in effect and an element is not found, either
  33. because the element number is out of range for the sequence or because
  34. filtering does not match the element type, a tuple will still be returned
  35. but both its elements will be empty.
  36. #include <boost/vmd/elem.hpp>
  37. #define BOOST_VMD_REGISTER_ANAME (ANAME) // an identifier must always be registered to be found by VMD
  38. #define A_SEQUENCE (1,2,3) 46 (list_data1,BOOST_PP_NIL) BOOST_VMD_TYPE_SEQ ANAME
  39. BOOST_VMD_ELEM(2,A_SEQUENCE) will return '(list_data1,BOOST_PP_NIL)'
  40. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_RETURN_NO_AFTER) will return '(list_data1,BOOST_PP_NIL)'
  41. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_RETURN_AFTER) will return '((list_data1,BOOST_PP_NIL),BOOST_VMD_TYPE_SEQ ANAME)'
  42. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_RETURN_ONLY_AFTER) will return 'BOOST_VMD_TYPE_SEQ ANAME'
  43. BOOST_VMD_ELEM(5,A_SEQUENCE) will return emptiness
  44. BOOST_VMD_ELEM(5,A_SEQUENCE,BOOST_VMD_RETURN_NO_AFTER) will return emptiness
  45. BOOST_VMD_ELEM(5,A_SEQUENCE,BOOST_VMD_RETURN_AFTER) will return '(,)'
  46. BOOST_VMD_ELEM(5,A_SEQUENCE,BOOST_VMD_RETURN_ONLY_AFTER) will return emptiness
  47. Combining splitting modifiers with return type modifiers:
  48. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_RETURN_AFTER,BOOST_VMD_RETURN_TYPE) will return '((BOOST_VMD_TYPE_LIST,(list_data1,BOOST_PP_NIL)),BOOST_VMD_TYPE_SEQ ANAME)'
  49. Combining splitting modifiers with filtering modifiers:
  50. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_RETURN_AFTER,BOOST_VMD_TYPE_LIST) will return '((list_data1,BOOST_PP_NIL),BOOST_VMD_TYPE_SEQ ANAME)'
  51. [endsect]