1 #ifndef BOOST_PREPROCESSOR_LIST_ADT_HPP
2 #define BOOST_PREPROCESSOR_LIST_ADT_HPP
6 * http://www.housemarque.com
8 * Permission to copy, use, modify, sell and distribute this software is
9 * granted provided this copyright notice appears in all copies. This
10 * software is provided "as is" without express or implied warranty, and
11 * with no claim as to its suitability for any purpose.
13 * See http://www.boost.org for most recent version.
16 /** <p>This header defines the fundamental list operations.</p>
20 <li>The internal representation of lists is hidden. Although there aren't
21 compelling reasons to change the representation, you should avoid
22 writing code that depends on the internal representation details.</li>
26 #include <boost/preprocessor/tuple/elem.hpp>
27 #include <boost/preprocessor/logical/not.hpp>
29 /** <p>List constructor.</p>
31 <p>Lists are build using list constructors BOOST_PP_LIST_NIL and
32 BOOST_PP_LIST_CONS(). For example,</p>
40 BOOST_PP_LIST_NIL)))))
43 <p>Short lists can also be build from tuples:</p>
46 BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5))
49 <p>Both of the above lists contain 5 elements: 1, 2, 3, 4 and 5.</p>
51 <p>Longer lists can be built from short lists with BOOST_PP_LIST_APPEND_D()
52 and BOOST_PP_LIST_FOLD_RIGHT():</p>
55 BOOST_PP_LIST_FOLD_RIGHT
56 ( BOOST_PP_LIST_APPEND_D
57 , BOOST_PP_TUPLE_TO_LIST
59 , BOOST_PP_TUPLE_TO_LIST(M, (E11, E12, ..., E1M) )
60 , BOOST_PP_TUPLE_TO_LIST(M, (E21, E22, ..., E2M) )
62 , BOOST_PP_TUPLE_TO_LIST(M, (EN1, EN2, ..., ENM) )
68 #define BOOST_PP_LIST_CONS(FIRST,REST) (FIRST,REST,1)
70 /** <p>List nil constructor.</p> */
71 #define BOOST_PP_LIST_NIL (_,_,0)
73 /** <p>Expands to 1 if the list is not nil and 0 otherwise.</p> */
74 #define BOOST_PP_LIST_IS_CONS(LIST) BOOST_PP_TUPLE_ELEM(3,2,LIST)
76 /** <p>Expands to 1 if the list is nil and 0 otherwise.</p> */
77 #define BOOST_PP_LIST_IS_NIL(LIST) BOOST_PP_NOT(BOOST_PP_TUPLE_ELEM(3,2,LIST))
79 /** <p>Expands to the first element of the list. The list must not be nil.</p>
84 BOOST_PP_LIST_FIRST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))
89 #define BOOST_PP_LIST_FIRST(LIST) BOOST_PP_TUPLE_ELEM(3,0,LIST)
91 /** <p>Expands to a list of all but the first element of the list.</p>
93 <p>The list must not be nil.</p>
98 BOOST_PP_LIST_REST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))
101 <p>expands to the same as:</p>
104 BOOST_PP_TUPLE_TO_LIST(4,(2,3,4,5))
107 #define BOOST_PP_LIST_REST(LIST) BOOST_PP_TUPLE_ELEM(3,1,LIST)