vmd_sequence_access.qbk 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_access Accessing a sequence element]
  8. It is possible to access an individual element of a sequence.
  9. The macro to do this is called BOOST_VMD_ELEM. The macro takes two
  10. required parameters. The required parameters are the element number
  11. to access and the sequence, in that order. The element number is a
  12. 0-based number and its maximum value should be one less than the size
  13. of the sequence.
  14. The BOOST_VMD_ELEM macro returns the actual sequence element. If the
  15. first required parameter is greater or equal to the size of the
  16. sequence the macro returns emptiness. Because of this using
  17. BOOST_VMD_ELEM on an empty sequence, whose size is 0, always returns
  18. emptiness.
  19. #include <boost/vmd/elem.hpp>
  20. #define BOOST_VMD_REGISTER_ANAME (ANAME)
  21. #define A_SEQUENCE (1,2,3) 46 (list_data1,(list_data2,BOOST_PP_NIL)) BOOST_VMD_TYPE_SEQ ANAME
  22. #define AN_EMPTY_SEQUENCE
  23. BOOST_VMD_ELEM(0,A_SEQUENCE) will return (1,2,3)
  24. BOOST_VMD_ELEM(1,A_SEQUENCE) will return 46
  25. BOOST_VMD_ELEM(2,A_SEQUENCE) will return (list_data1,(list_data2,BOOST_PP_NIL))
  26. BOOST_VMD_ELEM(3,A_SEQUENCE) will return BOOST_VMD_TYPE_SEQ
  27. BOOST_VMD_ELEM(4,A_SEQUENCE) will return ANAME
  28. BOOST_VMD_ELEM(5,A_SEQUENCE) will return emptiness
  29. BOOST_VMD_ELEM(0,AN_EMPTY_SEQUENCE) will return emptiness
  30. Accessing an element of a sequence directly is slower than accessing an element
  31. of a Boost PP data type or even variadic data, since each access has to directly
  32. cycle through each element of the sequence to get to the one being accessed.
  33. The process of sequentially parsing each element again each time is slower than
  34. accessing a Boost PP data type element.
  35. [heading Usage]
  36. You can use the general header file:
  37. #include <boost/vmd/vmd.hpp>
  38. or you can use the individual header file:
  39. #include <boost/vmd/elem.hpp>
  40. [endsect]