vmd_sequence_convert.qbk 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_sequence_convert Converting sequences]
  8. The easiest way to work with a sequence is to convert it to a Boost PP
  9. data type. Likewise you can also convert a sequence to variadic data even though the
  10. Boost PP data types have much greater functionality than variadic data in Boost PP.
  11. To convert a sequence to a Boost PP data type or variadic data the macros to be used are:
  12. * BOOST_VMD_TO_ARRAY(sequence) to convert the sequence to an array
  13. * BOOST_VMD_TO_LIST(sequence) to convert the sequence to a list
  14. * BOOST_VMD_TO_SEQ(sequence) to convert the sequence to a seq
  15. * BOOST_VMD_TO_TUPLE(sequence) to convert the sequence to a tuple
  16. * BOOST_VMD_ENUM(sequence) to convert the sequence to variadic data
  17. After the conversion the elements of a sequence become the elements
  18. of the corresponding composite data type.
  19. Once the elements of the sequence have been converted to the elements
  20. of the composite data type the full power of that composite data type can be used
  21. to process each element. Furthermore the programmer can use VMD to discover
  22. the type of an individual element for further processing.
  23. For single element sequences the result is always a single element composite
  24. data type. For multi-element sequences the result is always a composite data
  25. type of more than one element.
  26. For a sequence that is empty the result is emptiness when converting to
  27. a seq, tuple, or variadic data; the result is an empty array or list when
  28. converting to each of those composite data types respectively.
  29. #include <boost/vmd/enum.hpp>
  30. #include <boost/vmd/to_array.hpp>
  31. #include <boost/vmd/to_list.hpp>
  32. #include <boost/vmd/to_seq.hpp>
  33. #include <boost/vmd/to_tuple.hpp>
  34. #define BOOST_VMD_REGISTER_ANID (ANID)
  35. #define SEQUENCE_EMPTY
  36. #define SEQUENCE_SINGLE 35
  37. #define SEQUENCE_SINGLE_2 ANID
  38. #define SEQUENCE_MULTI (0,1) (2)(3)(4)
  39. #define SEQUENCE_MULTI_2 BOOST_VMD_TYPE_SEQ (2,(5,6))
  40. BOOST_VMD_TO_ARRAY(SEQUENCE_EMPTY) will return an empty array '(0,())'
  41. BOOST_VMD_TO_LIST(SEQUENCE_SINGLE) will return a one-element list '(35,BOOST_PP_NIL)'
  42. BOOST_VMD_TO_SEQ(SEQUENCE_SINGLE_2) will return a one-element seq '(ANID)'
  43. BOOST_VMD_TO_TUPLE(SEQUENCE_MULTI) will return a multi-element tuple '((0,1),(2)(3)(4))'
  44. BOOST_VMD_ENUM(SEQUENCE_MULTI_2) will return multi-element variadic data 'BOOST_VMD_TYPE_SEQ,(2,(5,6))'
  45. [heading Usage]
  46. You can use the general header file:
  47. #include <boost/vmd/vmd.hpp>
  48. or you can use individual header files for each of these macros.
  49. The individual header files are:
  50. #include <boost/vmd/to_array.hpp> // for the BOOST_VMD_TO_ARRAY macro
  51. #include <boost/vmd/to_list.hpp> // for the BOOST_VMD_TO_LIST macro
  52. #include <boost/vmd/to_seq.hpp> // for the BOOST_VMD_TO_SEQ macro
  53. #include <boost/vmd/to_tuple.hpp> // for the BOOST_VMD_TO_TUPLE macro.
  54. #include <boost/vmd/enum.hpp> // for the BOOST_VMD_ENUM macro.
  55. [endsect]