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