]> git.lyx.org Git - lyx.git/blob - boost/boost/preprocessor/list/adt.hpp
update
[lyx.git] / boost / boost / preprocessor / list / adt.hpp
1 #ifndef BOOST_PREPROCESSOR_LIST_ADT_HPP
2 #define BOOST_PREPROCESSOR_LIST_ADT_HPP
3
4 /* Copyright (C) 2001
5  * Housemarque Oy
6  * http://www.housemarque.com
7  *
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.
12  *
13  * See http://www.boost.org for most recent version.
14  */
15
16 /** <p>This header defines the fundamental list operations.</p>
17
18 <h3>Note</h3>
19 <ul>
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>
23 </ul>
24 */
25
26 #include <boost/preprocessor/tuple/elem.hpp>
27 #include <boost/preprocessor/logical/not.hpp>
28
29 /** <p>List constructor.</p>
30
31 <p>Lists are build using list constructors BOOST_PP_LIST_NIL and
32 BOOST_PP_LIST_CONS(). For example,</p>
33
34 <pre>
35 BOOST_PP_LIST_CONS(1,
36 BOOST_PP_LIST_CONS(2,
37 BOOST_PP_LIST_CONS(3,
38 BOOST_PP_LIST_CONS(4,
39 BOOST_PP_LIST_CONS(5,
40 BOOST_PP_LIST_NIL)))))
41 </pre>
42
43 <p>Short lists can also be build from tuples:</p>
44
45 <pre>
46 BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5))
47 </pre>
48
49 <p>Both of the above lists contain 5 elements: 1, 2, 3, 4 and 5.</p>
50
51 <p>Longer lists can be built from short lists with BOOST_PP_LIST_APPEND_D()
52 and BOOST_PP_LIST_FOLD_RIGHT():</p>
53
54 <pre>
55 BOOST_PP_LIST_FOLD_RIGHT
56 ( BOOST_PP_LIST_APPEND_D
57 , BOOST_PP_TUPLE_TO_LIST
58   ( N
59   , BOOST_PP_TUPLE_TO_LIST(M, (E11, E12, ..., E1M) )
60   , BOOST_PP_TUPLE_TO_LIST(M, (E21, E22, ..., E2M) )
61   , ...
62   , BOOST_PP_TUPLE_TO_LIST(M, (EN1, EN2, ..., ENM) )
63   )
64 , BOOST_PP_LIST_NIL
65 )
66 </pre>
67 */
68 #define BOOST_PP_LIST_CONS(FIRST,REST) (FIRST,REST,1)
69
70 /** <p>List nil constructor.</p> */
71 #define BOOST_PP_LIST_NIL (_,_,0)
72
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)
75
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))
78
79 /** <p>Expands to the first element of the list. The list must not be nil.</p>
80
81 <p>For example,</p>
82
83 <pre>
84 BOOST_PP_LIST_FIRST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))
85 </pre>
86
87 <p>expands to 1.</p>
88 */
89 #define BOOST_PP_LIST_FIRST(LIST) BOOST_PP_TUPLE_ELEM(3,0,LIST)
90
91 /** <p>Expands to a list of all but the first element of the list.</p>
92
93 <p>The list must not be nil.</p>
94
95 <p>For example,</p>
96
97 <pre>
98 BOOST_PP_LIST_REST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))
99 </pre>
100
101 <p>expands to the same as:</p>
102
103 <pre>
104 BOOST_PP_TUPLE_TO_LIST(4,(2,3,4,5))
105 </pre>
106 */
107 #define BOOST_PP_LIST_REST(LIST) BOOST_PP_TUPLE_ELEM(3,1,LIST)
108 #endif