• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 # /* **************************************************************************
2 #  *                                                                          *
3 #  *     (C) Copyright Paul Mensonides 2002.
4 #  *     Distributed under the Boost Software License, Version 1.0. (See
5 #  *     accompanying file LICENSE_1_0.txt or copy at
6 #  *     http://www.boost.org/LICENSE_1_0.txt)
7 #  *                                                                          *
8 #  ************************************************************************** */
9 #
10 # /* Revised by Edward Diener (2011) */
11 #
12 # /* See http://www.boost.org for most recent version. */
13 #
14 # include <boost/preprocessor/arithmetic/add.hpp>
15 # include <boost/preprocessor/arithmetic/sub.hpp>
16 # include <boost/preprocessor/comparison/equal.hpp>
17 # include <boost/preprocessor/comparison/less.hpp>
18 # include <boost/preprocessor/control/iif.hpp>
19 # include <boost/preprocessor/facilities/is_empty.hpp>
20 # include <boost/preprocessor/list.hpp>
21 # include <boost/preprocessor/tuple/elem.hpp>
22 # include <boost/preprocessor/tuple/size.hpp>
23 # include <boost/preprocessor/array/elem.hpp>
24 # include <boost/preprocessor/array/size.hpp>
25 # include <boost/preprocessor/seq/elem.hpp>
26 # include <boost/preprocessor/seq/size.hpp>
27 # include <boost/preprocessor/variadic/elem.hpp>
28 # include <libs/preprocessor/test/test.h>
29 
30 # define LISTNIL BOOST_PP_NIL
31 # define LIST (4, (1, (5, (2, BOOST_PP_NIL))))
32 # define REVERSAL(d, x, y) BOOST_PP_SUB_D(d, y, x)
33 # define F1(r, state, x) + x + state
34 # define FI2(r, state, i, x) BOOST_PP_IIF(BOOST_PP_EQUAL(i,1),+ x + x + state,+ x + state)
35 # define F2(r, x) + BOOST_PP_TUPLE_ELEM(2, 0, x) + 2 - BOOST_PP_TUPLE_ELEM(2, 1, x)
36 # define L1 (0, (x, BOOST_PP_NIL))
37 # define L2 (a, (1, (b, (2, BOOST_PP_NIL))))
38 # define L3 (c, (3, (d, BOOST_PP_NIL)))
39 # define LL (L1, (L2, (L3, BOOST_PP_NIL)))
40 
41 BEGIN BOOST_PP_LIST_FIRST(LIST) == 4 END
42 BEGIN BOOST_PP_LIST_IS_CONS(LIST) == 1 END
43 BEGIN BOOST_PP_LIST_IS_CONS(LISTNIL) == 0 END
44 BEGIN BOOST_PP_LIST_IS_NIL(LIST) == 0 END
45 BEGIN BOOST_PP_LIST_IS_NIL(LISTNIL) == 1 END
46 
47 #if BOOST_PP_VARIADICS
48 
49 BEGIN BOOST_PP_VARIADIC_ELEM(2,BOOST_PP_LIST_ENUM(LIST)) == 5 END
50 
51 #endif
52 
53 BEGIN BOOST_PP_LIST_FOLD_LEFT(BOOST_PP_SUB_D, 22, LIST) == 10 END
54 BEGIN BOOST_PP_LIST_FOLD_LEFT(BOOST_PP_SUB_D, 22, LISTNIL) == 22 END
55 BEGIN BOOST_PP_LIST_FOLD_RIGHT(BOOST_PP_ADD_D, 0, LIST) == 12 END
56 BEGIN BOOST_PP_LIST_FOLD_RIGHT(BOOST_PP_ADD_D, 0, LISTNIL) == 0 END
57 BEGIN BOOST_PP_LIST_FOLD_RIGHT(REVERSAL, 0, LIST) == 4 END
58 
59 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_REVERSE(LIST)) == 2514 END
60 BEGIN BOOST_PP_LIST_IS_NIL(BOOST_PP_LIST_REVERSE(LISTNIL)) == 1 END
61 
62 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_REST_N(2, LIST)) == 52 END
63 BEGIN BOOST_PP_LIST_IS_NIL(BOOST_PP_LIST_REST_N(0, LISTNIL)) == 1 END
64 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_FIRST_N(2, LIST)) == 41 END
65 
66 BEGIN BOOST_PP_LIST_AT(LIST, 2) == 5 END
67 BEGIN BOOST_PP_LIST_SIZE(LIST) == 4 END
68 BEGIN BOOST_PP_LIST_SIZE(LISTNIL) == 0 END
69 
70 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_TRANSFORM(BOOST_PP_ADD_D, 2, LIST)) == 6374 END
71 BEGIN BOOST_PP_LIST_IS_NIL(BOOST_PP_LIST_TRANSFORM(BOOST_PP_ADD_D, 2, LISTNIL)) == 1 END
72 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_APPEND(BOOST_PP_LIST_REST(LIST), LIST)) == 1524152 END
73 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_APPEND(LIST,LISTNIL)) == 4152 END
74 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_APPEND(LISTNIL,LIST)) == 4152 END
75 BEGIN BOOST_PP_LIST_IS_NIL(BOOST_PP_LIST_APPEND(LISTNIL,LISTNIL)) == 1 END
76 
77 BEGIN BOOST_PP_LIST_FOR_EACH(F1, 1, LIST) == 16 END
78 BEGIN BOOST_PP_LIST_FOR_EACH_I(FI2, 1, LIST) == 17 END
79 
80 BEGIN BOOST_PP_TUPLE_ELEM(4, 3, BOOST_PP_LIST_TO_TUPLE(LIST)) == 2 END
81 
82 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_FILTER(BOOST_PP_LESS_D, 3, LIST)) == 45 END
83 BEGIN BOOST_PP_LIST_IS_NIL(BOOST_PP_LIST_FILTER(BOOST_PP_LESS_D, 3, LISTNIL)) == 1 END
84 
85 BEGIN BOOST_PP_LIST_FOR_EACH_PRODUCT(F2, 2, ( (1, (0, BOOST_PP_NIL)), (2, (3, BOOST_PP_NIL)) )) == 0 END
86 
87 BEGIN BOOST_PP_LIST_CAT(BOOST_PP_LIST_FOLD_LEFT(BOOST_PP_LIST_APPEND_D, BOOST_PP_NIL, LL)) == 0x0a1b2c3d END
88 
89 BEGIN BOOST_PP_ARRAY_ELEM(2, BOOST_PP_LIST_TO_ARRAY(LIST)) == 5 END
90 BEGIN BOOST_PP_ARRAY_SIZE(BOOST_PP_LIST_TO_ARRAY(LISTNIL)) == 0 END
91 BEGIN BOOST_PP_SEQ_ELEM(3, BOOST_PP_LIST_TO_SEQ(LIST)) == 2 END
92