123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- [/
- (C) Copyright Edward Diener 2011-2015
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt).
- ]
- [section:vmd_sequence_access Accessing a sequence element]
- It is possible to access an individual element of a sequence.
- The macro to do this is called BOOST_VMD_ELEM. The macro takes two
- required parameters. The required parameters are the element number
- to access and the sequence, in that order. The element number is a
- 0-based number and its maximum value should be one less than the size
- of the sequence.
- The BOOST_VMD_ELEM macro returns the actual sequence element. If the
- first required parameter is greater or equal to the size of the
- sequence the macro returns emptiness. Because of this using
- BOOST_VMD_ELEM on an empty sequence, whose size is 0, always returns
- emptiness.
- #include <boost/vmd/elem.hpp>
-
- #define BOOST_VMD_REGISTER_ANAME (ANAME)
- #define A_SEQUENCE (1,2,3) 46 (list_data1,(list_data2,BOOST_PP_NIL)) BOOST_VMD_TYPE_SEQ ANAME
- #define AN_EMPTY_SEQUENCE
-
- BOOST_VMD_ELEM(0,A_SEQUENCE) will return (1,2,3)
- BOOST_VMD_ELEM(1,A_SEQUENCE) will return 46
- BOOST_VMD_ELEM(2,A_SEQUENCE) will return (list_data1,(list_data2,BOOST_PP_NIL))
- BOOST_VMD_ELEM(3,A_SEQUENCE) will return BOOST_VMD_TYPE_SEQ
- BOOST_VMD_ELEM(4,A_SEQUENCE) will return ANAME
-
- BOOST_VMD_ELEM(5,A_SEQUENCE) will return emptiness
- BOOST_VMD_ELEM(0,AN_EMPTY_SEQUENCE) will return emptiness
-
- Accessing an element of a sequence directly is slower than accessing an element
- of a Boost PP data type or even variadic data, since each access has to directly
- cycle through each element of the sequence to get to the one being accessed.
- The process of sequentially parsing each element again each time is slower than
- accessing a Boost PP data type element.
- [heading Usage]
- You can use the general header file:
- #include <boost/vmd/vmd.hpp>
-
- or you can use the individual header file:
- #include <boost/vmd/elem.hpp>
- [endsect]
|