diff --git a/include/boost/preprocessor/list.hpp b/include/boost/preprocessor/list.hpp new file mode 100644 index 0000000..a23ae65 --- /dev/null +++ b/include/boost/preprocessor/list.hpp @@ -0,0 +1,30 @@ +#ifndef BOOST_PREPROCESSOR_LIST_HPP +#define BOOST_PREPROCESSOR_LIST_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. + +Includes all list headers. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#endif diff --git a/include/boost/preprocessor/list/adt.hpp b/include/boost/preprocessor/list/adt.hpp new file mode 100644 index 0000000..25cd79f --- /dev/null +++ b/include/boost/preprocessor/list/adt.hpp @@ -0,0 +1,98 @@ +#ifndef BOOST_PREPROCESSOR_LIST_ADT_HPP +#define BOOST_PREPROCESSOR_LIST_ADT_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. + +This header defines the fundamental list operations. + +NOTE: The internal representation of lists is hidden. Although there aren't +compelling reasons to change the representation, you should avoid writing +code that depends on the internal representation details. +*/ + +#include +#include + +//! List constructor. +/*! +Lists are build using list constructors BOOST_PP_LIST_NIL and +BOOST_PP_LIST_CONS(). For example, + +
\verbatim
+  BOOST_PP_LIST_CONS(1,
+  BOOST_PP_LIST_CONS(2,
+  BOOST_PP_LIST_CONS(3,
+  BOOST_PP_LIST_CONS(4,
+  BOOST_PP_LIST_CONS(5,
+  BOOST_PP_LIST_NIL)))))
+\endverbatim
+ +Short lists can also be build from tuples: + +
\verbatim
+  BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5))
+\endverbatim
+ +Both of the above lists contain 5 elements: 1, 2, 3, 4 and 5. +*/ +#define BOOST_PP_LIST_CONS(H,T) (H,T,1) + +//! List nil constructor. +/*! +See BOOST_PP_LIST_CONS(). +*/ +#define BOOST_PP_LIST_NIL (_,_,0) + +//! Expands to 1 if the list is not nil and 0 otherwise. +/*! +See BOOST_PP_LIST_IS_NIL(). +*/ +#define BOOST_PP_LIST_IS_CONS(L) BOOST_PP_TUPLE_ELEM(3,2,L) + +//! Expands to 1 if the list is nil and 0 otherwise. +/*! +See BOOST_PP_LIST_IS_CONS(). +*/ +#define BOOST_PP_LIST_IS_NIL(L) BOOST_PP_NOT(BOOST_PP_TUPLE_ELEM(3,2,L)) + +//! Expands to the first element of the list. The list must not be nil. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_FIRST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))
+\endverbatim
+ +expands to 1. + +See BOOST_PP_LIST_REST(). +*/ +#define BOOST_PP_LIST_FIRST(L) BOOST_PP_TUPLE_ELEM(3,0,L) + +//! Expands to a list of all but the first element of the list. The list must not be nil. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_REST(BOOST_PP_TUPLE_TO_LIST(5,(1,2,3,4,5)))
+\endverbatim
+ +expands to a list containing 2, 3, 4 and 5. + +See BOOST_PP_LIST_FIRST(). +*/ +#define BOOST_PP_LIST_REST(L) BOOST_PP_TUPLE_ELEM(3,1,L) +#endif diff --git a/include/boost/preprocessor/list/append.hpp b/include/boost/preprocessor/list/append.hpp new file mode 100644 index 0000000..d9ab752 --- /dev/null +++ b/include/boost/preprocessor/list/append.hpp @@ -0,0 +1,41 @@ +#ifndef BOOST_PREPROCESSOR_LIST_APPEND_HPP +#define BOOST_PREPROCESSOR_LIST_APPEND_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include + +//! Catenates two lists together. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_APPEND
+  ( BOOST_PP_TUPLE_TO_LIST(2,(1,2))
+  , BOOST_PP_TUPLE_TO_LIST(2,(3,4))
+  )
+\endverbatim
+ +produces a list containing 1, 2, 3 and 4. +*/ +#define BOOST_PP_LIST_APPEND(L,P) BOOST_PP_LIST_APPEND_D(0,L,P) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_APPEND_D(D,L,P) BOOST_PP_LIST_FOLD_RIGHT_D(D,BOOST_PP_LIST_APPEND_F,L,P) +#define BOOST_PP_LIST_APPEND_F(D,H,P) BOOST_PP_LIST_CONS(H,P) +#endif +#endif diff --git a/include/boost/preprocessor/list/at.hpp b/include/boost/preprocessor/list/at.hpp new file mode 100644 index 0000000..a2474a0 --- /dev/null +++ b/include/boost/preprocessor/list/at.hpp @@ -0,0 +1,37 @@ +#ifndef BOOST_PFIRST_NPROCESSOR_LIST_AT_HPP +#define BOOST_PFIRST_NPROCESSOR_LIST_AT_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this softwaFIRST_N is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include + +//! Expands to the I:th element of the list L. The first element is at index 0. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_AT(BOOST_PP_TUPLE_TO_LIST(3,(A,B,C)),1)
+\endverbatim
+ +expands to B. +*/ +#define BOOST_PP_LIST_AT(L,I) BOOST_PP_LIST_AT_D(0,L,I) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_AT_D(D,L,I) BOOST_PP_LIST_FIRST(BOOST_PP_LIST_REST_N_D(D,I,L)) +#endif +#endif diff --git a/include/boost/preprocessor/list/cat.hpp b/include/boost/preprocessor/list/cat.hpp new file mode 100644 index 0000000..695a01c --- /dev/null +++ b/include/boost/preprocessor/list/cat.hpp @@ -0,0 +1,39 @@ +#ifndef BOOST_PREPROCESSOR_LIST_CAT_HPP +#define BOOST_PREPROCESSOR_LIST_CAT_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include + +//! Catenates all elements of the list. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_CAT(BOOST_PP_TUPLE_TO_LIST(3,(1,2,3)))
+\endverbatim
+ +expands to 123. +*/ +#define BOOST_PP_LIST_CAT(L) BOOST_PP_LIST_CAT_D(0,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_CAT_D(D,L) BOOST_PP_LIST_FOLD_LEFT_D(D,BOOST_PP_LIST_CAT_F,BOOST_PP_LIST_FIRST(L),BOOST_PP_LIST_REST(L)) +#define BOOST_PP_LIST_CAT_F(D,P,H) BOOST_PP_CAT(P,H) +#endif +#endif diff --git a/include/boost/preprocessor/list/enum.hpp b/include/boost/preprocessor/list/enum.hpp new file mode 100644 index 0000000..4667c3f --- /dev/null +++ b/include/boost/preprocessor/list/enum.hpp @@ -0,0 +1,43 @@ +#ifndef BOOST_PREPROCESSOR_LIST_ENUM_HPP +#define BOOST_PREPROCESSOR_LIST_ENUM_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include + +//! Converts the list to a comma separated list. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_ENUM(BOOST_PP_TUPLE_TO_LIST(3,(A,B,C)))
+\endverbatim
+ +expands to: + +
\verbatim
+  A, B, C
+\endverbatim
+*/ +#define BOOST_PP_LIST_ENUM(L) BOOST_PP_LIST_ENUM_R(0,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_ENUM_R(R,L) BOOST_PP_LIST_FOR_EACH_R(R,BOOST_PP_LIST_ENUM_F,_,L) +#define BOOST_PP_LIST_ENUM_F(I,_,X) BOOST_PP_COMMA_IF(I) X +#endif +#endif diff --git a/include/boost/preprocessor/list/filter.hpp b/include/boost/preprocessor/list/filter.hpp new file mode 100644 index 0000000..1f3e3c9 --- /dev/null +++ b/include/boost/preprocessor/list/filter.hpp @@ -0,0 +1,38 @@ +#ifndef BOOST_PREPROCESSOR_LIST_FILTER_HPP +#define BOOST_PREPROCESSOR_LIST_FILTER_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include + +//! Expands to a list containing all the elements X of the list for which F(D,P,X) is true. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_FILTER(BOOST_PP_NOT_EQUAL_D,2,BOOST_PP_TUPLE_TO_LIST(3,(1,2,3)))
+\endverbatim
+ +expands to a list containing 1 and 3. +*/ +#define BOOST_PP_LIST_FILTER(F,P,L) BOOST_PP_LIST_FILTER_D(0,F,P,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_FILTER_D(D,F,P,L) BOOST_PP_TUPLE_ELEM(3,2,BOOST_PP_LIST_FOLD_RIGHT_D(D,BOOST_PP_LIST_FILTER_F,L,(F,P,BOOST_PP_LIST_NIL))) +#define BOOST_PP_LIST_FILTER_F(D,H,P) (BOOST_PP_TUPLE_ELEM(3,0,P),BOOST_PP_TUPLE_ELEM(3,1,P),BOOST_PP_IF(BOOST_PP_TUPLE_ELEM(3,0,P)(D,BOOST_PP_TUPLE_ELEM(3,1,P),H),BOOST_PP_LIST_CONS,BOOST_PP_TUPLE2_ELEM1)(H,BOOST_PP_TUPLE_ELEM(3,2,P))) +#endif +#endif diff --git a/include/boost/preprocessor/list/first_n.hpp b/include/boost/preprocessor/list/first_n.hpp new file mode 100644 index 0000000..2af3827 --- /dev/null +++ b/include/boost/preprocessor/list/first_n.hpp @@ -0,0 +1,41 @@ +#ifndef BOOST_PREPROCESSOR_LIST_FIRST_N_HPP +#define BOOST_PREPROCESSOR_LIST_FIRST_N_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include +#include + +//! Expands to a list of the first N elements of the list. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_FIRST_N(2,BOOST_PP_TUPLE_TO_LIST(4,(+,-,*,/)))
+\endverbatim
+ +expands to a list containing + and -. +*/ +#define BOOST_PP_LIST_FIRST_N(N,L) BOOST_PP_LIST_FIRST_N_D(0,N,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_FIRST_N_D(D,N,L) BOOST_PP_LIST_REVERSE_D(D,BOOST_PP_TUPLE_ELEM(3,0,BOOST_PP_WHILE##D(BOOST_PP_LIST_FIRST_N_C,BOOST_PP_LIST_FIRST_N_F,(BOOST_PP_LIST_NIL,L,N)))) +#define BOOST_PP_LIST_FIRST_N_C(D,X) BOOST_PP_TUPLE_ELEM(3,2,X) +#define BOOST_PP_LIST_FIRST_N_F(D,X) (BOOST_PP_LIST_CONS(BOOST_PP_LIST_FIRST(BOOST_PP_TUPLE_ELEM(3,1,X)),BOOST_PP_TUPLE_ELEM(3,0,X)),BOOST_PP_LIST_REST(BOOST_PP_TUPLE_ELEM(3,1,X)),BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(3,2,X))) +#endif +#endif diff --git a/include/boost/preprocessor/list/fold_left.hpp b/include/boost/preprocessor/list/fold_left.hpp new file mode 100644 index 0000000..5c21b5b --- /dev/null +++ b/include/boost/preprocessor/list/fold_left.hpp @@ -0,0 +1,53 @@ +#ifndef BOOST_PREPROCESSOR_LIST_FOLD_LEFT_HPP +#define BOOST_PREPROCESSOR_LIST_FOLD_LEFT_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include + +//! Iterates F(D,P,X) for each element X of the list L (from the left or the start of the list). +/*! +In other words, + +
\verbatim
+  BOOST_PP_LIST_FOLD_LEFT(F,P,L)
+\endverbatim
+ +expands to: + +
\verbatim
+  F
+  ( D
+  , ... F(D, F(D,P,BOOST_PP_LIST_AT(L,0)), BOOST_PP_LIST_AT(L,1)) ...
+  , BOOST_PP_LIST_AT(L,BOOST_PP_DEC(BOOST_PP_LIST_SIZE(L))
+  )
+\endverbatim
+ +Note that folding, or accumulation, is a very general pattern of computation. +Most list operations can implemented in terms of folding. + +See BOOST_PP_LIST_FOLD_RIGHT(). +*/ +#define BOOST_PP_LIST_FOLD_LEFT(F,P,L) BOOST_PP_LIST_FOLD_LEFT_D(0,F,P,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_FOLD_LEFT_D(D,F,P,L) BOOST_PP_TUPLE_ELEM(3,1,BOOST_PP_WHILE##D(BOOST_PP_LIST_FOLD_LEFT_C,BOOST_PP_LIST_FOLD_LEFT_F,(F,P,L))) +#define BOOST_PP_LIST_FOLD_LEFT_C(D,X) BOOST_PP_LIST_IS_CONS(BOOST_PP_TUPLE_ELEM(3,2,X)) +#define BOOST_PP_LIST_FOLD_LEFT_F(D,X) (BOOST_PP_TUPLE_ELEM(3,0,X),BOOST_PP_TUPLE_ELEM(3,0,X)(D,BOOST_PP_TUPLE_ELEM(3,1,X),BOOST_PP_LIST_FIRST(BOOST_PP_TUPLE_ELEM(3,2,X))),BOOST_PP_LIST_REST(BOOST_PP_TUPLE_ELEM(3,2,X))) +#endif +#endif diff --git a/include/boost/preprocessor/list/fold_right.hpp b/include/boost/preprocessor/list/fold_right.hpp new file mode 100644 index 0000000..885519e --- /dev/null +++ b/include/boost/preprocessor/list/fold_right.hpp @@ -0,0 +1,56 @@ +#ifndef BOOST_PREPROCESSOR_LIST_FOLD_RIGHT_HPP +#define BOOST_PREPROCESSOR_LIST_FOLD_RIGHT_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include + +//! Iterates F(D,X,P) for each element X of the list L (from the right or the end of the list). +/*! +In other words, + +
\verbatim
+  BOOST_PP_LIST_FOLD_RIGHT(F,L,P)
+\endverbatim
+ +expands to: + +
\verbatim
+  F
+  ( D
+  , BOOST_PP_LIST_AT(L,0)
+  , ... F
+        ( D
+        , BOOST_PP_LIST_AT(L,BOOST_PP_SUB(BOOST_PP_LIST_SIZE(L),2))
+        , F
+          ( D
+          , BOOST_PP_LIST_AT(L,BOOST_PP_SUB(BOOST_PP_LIST_SIZE(L),1))
+          , P
+          )
+        ) ...
+  )
+\endverbatim
+ +See BOOST_PP_LIST_FOLD_LEFT(). +*/ +#define BOOST_PP_LIST_FOLD_RIGHT(F,L,P) BOOST_PP_LIST_FOLD_RIGHT_D(0,F,L,P) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_FOLD_RIGHT_D(D,F,L,P) BOOST_PP_TUPLE_ELEM(2,1,BOOST_PP_LIST_FOLD_LEFT_D(D,BOOST_PP_LIST_FOLD_RIGHT_F,(F,P),BOOST_PP_LIST_REVERSE_D(D,L))) +#define BOOST_PP_LIST_FOLD_RIGHT_F(D,FR,H) (BOOST_PP_TUPLE_ELEM(2,0,FR),BOOST_PP_TUPLE_ELEM(2,0,FR)(D,H,BOOST_PP_TUPLE_ELEM(2,1,FR))) +#endif +#endif diff --git a/include/boost/preprocessor/list/for_each.hpp b/include/boost/preprocessor/list/for_each.hpp new file mode 100644 index 0000000..086eb18 --- /dev/null +++ b/include/boost/preprocessor/list/for_each.hpp @@ -0,0 +1,44 @@ +#ifndef BOOST_PREPROCESSOR_LIST_FOR_EACH_HPP +#define BOOST_PREPROCESSOR_LIST_FOR_EACH_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include + +//! Repeats F(R,P,BOOST_PP_LIST_AT(L,I)) for each I = [0,BOOST_PP_LIST_SIZE(L)[. +/*! +In other words, expands to the sequence: + +
\verbatim
+  F(R,P,BOOST_PP_LIST_AT(L,0))
+  F(R,P,BOOST_PP_LIST_AT(L,1))
+  ...
+  F(R,P,BOOST_PP_LIST_AT(L,BOOST_PP_DEC(BOOST_PP_LIST_SIZE(L))))
+\endverbatim
+ +See BOOST_PP_FOR() for an explanation of the R parameter. +*/ +#define BOOST_PP_LIST_FOR_EACH(F,P,L) BOOST_PP_LIST_FOR_EACH_R(0,F,P,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_FOR_EACH_R(R,F,P,L) BOOST_PP_FOR##R((F,P,L,0),BOOST_PP_LIST_FOR_EACH_C,BOOST_PP_LIST_FOR_EACH_F,BOOST_PP_LIST_FOR_EACH_I) +#define BOOST_PP_LIST_FOR_EACH_C(R,FPL) BOOST_PP_LIST_IS_CONS(BOOST_PP_TUPLE_ELEM(4,2,FPL)) +#define BOOST_PP_LIST_FOR_EACH_F(R,FPL) (BOOST_PP_TUPLE_ELEM(4,0,FPL),BOOST_PP_TUPLE_ELEM(4,1,FPL),BOOST_PP_LIST_REST(BOOST_PP_TUPLE_ELEM(4,2,FPL)),BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(4,3,FPL))) +#define BOOST_PP_LIST_FOR_EACH_I(R,FPL) BOOST_PP_EXPAND(BOOST_PP_TUPLE_ELEM(4,0,FPL)(BOOST_PP_TUPLE_ELEM(4,3,FPL),BOOST_PP_TUPLE_ELEM(4,1,FPL),BOOST_PP_LIST_FIRST(BOOST_PP_TUPLE_ELEM(4,2,FPL)))) +#endif +#endif diff --git a/include/boost/preprocessor/list/rest_n.hpp b/include/boost/preprocessor/list/rest_n.hpp new file mode 100644 index 0000000..b54c2eb --- /dev/null +++ b/include/boost/preprocessor/list/rest_n.hpp @@ -0,0 +1,41 @@ +#ifndef BOOST_PREPROCESSOR_LIST_REST_N_HPP +#define BOOST_PREPROCESSOR_LIST_REST_N_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include +#include + +//! Expands to a list of all but the first N elements of the list. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_REST_N(2,BOOST_PP_TUPLE_TO_LIST(4,(+,-,*,/)))
+\endverbatim
+ +expands to a list containing * and /. +*/ +#define BOOST_PP_LIST_REST_N(N,L) BOOST_PP_LIST_REST_N_D(0,N,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_REST_N_D(D,N,L) BOOST_PP_TUPLE_ELEM(2,0,BOOST_PP_WHILE##D(BOOST_PP_LIST_REST_N_C,BOOST_PP_LIST_REST_N_F,(L,N))) +#define BOOST_PP_LIST_REST_N_C(D,X) BOOST_PP_TUPLE_ELEM(2,1,X) +#define BOOST_PP_LIST_REST_N_F(D,X) (BOOST_PP_LIST_REST(BOOST_PP_TUPLE_ELEM(2,0,X)),BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(2,1,X))) +#endif +#endif diff --git a/include/boost/preprocessor/list/reverse.hpp b/include/boost/preprocessor/list/reverse.hpp new file mode 100644 index 0000000..6e2960f --- /dev/null +++ b/include/boost/preprocessor/list/reverse.hpp @@ -0,0 +1,38 @@ +#ifndef BOOST_PREPROCESSOR_LIST_REVERSE_HPP +#define BOOST_PREPROCESSOR_LIST_REVERSE_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include + +//! List reversal. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_REVERSE(BOOST_PP_TUPLE_TO_LIST(3,(A,B,C)))
+\endverbatim
+ +expands to a list containing C, B and A. +*/ +#define BOOST_PP_LIST_REVERSE(L) BOOST_PP_LIST_REVERSE_D(0,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_REVERSE_D(D,L) BOOST_PP_LIST_FOLD_LEFT_D(D,BOOST_PP_LIST_REVERSE_F,BOOST_PP_LIST_NIL,L) +#define BOOST_PP_LIST_REVERSE_F(D,P,H) BOOST_PP_LIST_CONS(H,P) +#endif +#endif diff --git a/include/boost/preprocessor/list/size.hpp b/include/boost/preprocessor/list/size.hpp new file mode 100644 index 0000000..0c64cd4 --- /dev/null +++ b/include/boost/preprocessor/list/size.hpp @@ -0,0 +1,39 @@ +#ifndef BOOST_PREPROCESSOR_LIST_SIZE_HPP +#define BOOST_PREPROCESSOR_LIST_SIZE_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include + +//! Expands to the number of elements in the list. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_SIZE(BOOST_PP_TUPLE_TO_LIST(3,(A,B,C)))
+\endverbatim
+ +expands to 3. +*/ +#define BOOST_PP_LIST_SIZE(L) BOOST_PP_LIST_SIZE_D(0,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_SIZE_D(D,L) BOOST_PP_LIST_FOLD_LEFT_D(D,BOOST_PP_LIST_SIZE_F,0,L) +#define BOOST_PP_LIST_SIZE_F(D,P,H) BOOST_PP_INC(P) +#endif +#endif diff --git a/include/boost/preprocessor/list/to_tuple.hpp b/include/boost/preprocessor/list/to_tuple.hpp new file mode 100644 index 0000000..a0d4249 --- /dev/null +++ b/include/boost/preprocessor/list/to_tuple.hpp @@ -0,0 +1,41 @@ +#ifndef BOOST_PREPROCESSOR_LIST_TO_TUPLE_HPP +#define BOOST_PREPROCESSOR_LIST_TO_TUPLE_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include +#include + +//! Converts the list to a tuple. +/*! +For example, + +
\verbatim
+  BOOST_PP_LIST_TO_TUPLE(BOOST_PP_TUPLE_TO_LIST(3,(A,B,C)))
+\endverbatim
+ +expands to (A,B,C). + +NOTE: The supported size of the list being converted to a tuple is limited by +BOOST_PP_LIMIT_MAG rather than BOOST_PP_LIMIT_TUPLE. +*/ +#define BOOST_PP_LIST_TO_TUPLE(L) BOOST_PP_LIST_TO_TUPLE_R(0,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_TO_TUPLE_R(D,L) (BOOST_PP_LIST_ENUM_R(D,L)) +#endif +#endif diff --git a/include/boost/preprocessor/list/transform.hpp b/include/boost/preprocessor/list/transform.hpp new file mode 100644 index 0000000..d1fd211 --- /dev/null +++ b/include/boost/preprocessor/list/transform.hpp @@ -0,0 +1,48 @@ +#ifndef BOOST_PREPROCESSOR_LIST_TRANSFORM_HPP +#define BOOST_PREPROCESSOR_LIST_TRANSFORM_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include + +//! Applies the macro F(D,P,X) to each element X of the list producing a new list. +/*! +In other words, BOOST_PP_LIST_TRANSFORM(F,P,L) expands to same as: + +
\verbatim
+  BOOST_PP_LIST_CONS(F(D,P,BOOST_PP_LIST_AT(L,0)),
+  BOOST_PP_LIST_CONS(F(D,P,BOOST_PP_LIST_AT(L,1)),
+  ...
+  BOOST_PP_LIST_CONS(F(D,P,BOOST_PP_LIST_AT(L,BOOST_PP_DEC(BOOST_PP_LIST_SIZE(L)))),
+  BOOST_PP_LIST_NIL) ... ))
+\endverbatim
+ +For example, + +
\verbatim
+  BOOST_PP_LIST_TRANSFORM(BOOST_PP_ADD_D,2,BOOST_PP_TUPLE_TO_LIST(2,(1,2)))
+\endverbatim
+ +expands to a list containing 3 and 4. +*/ +#define BOOST_PP_LIST_TRANSFORM(F,P,L) BOOST_PP_LIST_TRANSFORM_D(0,F,P,L) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_LIST_TRANSFORM_D(D,F,P,L) BOOST_PP_TUPLE_ELEM(3,2,BOOST_PP_LIST_FOLD_RIGHT_D(D,BOOST_PP_LIST_TRANSFORM_F,L,(F,P,BOOST_PP_LIST_NIL))) +#define BOOST_PP_LIST_TRANSFORM_F(D,H,P) (BOOST_PP_TUPLE_ELEM(3,0,P),BOOST_PP_TUPLE_ELEM(3,1,P),BOOST_PP_LIST_CONS(BOOST_PP_EXPAND(BOOST_PP_TUPLE_ELEM(3,0,P)(D,BOOST_PP_TUPLE_ELEM(3,1,P),H)),BOOST_PP_TUPLE_ELEM(3,2,P))) +#endif +#endif diff --git a/include/boost/preprocessor/repeat.hpp b/include/boost/preprocessor/repeat.hpp index 9de5223..4af8a6c 100644 --- a/include/boost/preprocessor/repeat.hpp +++ b/include/boost/preprocessor/repeat.hpp @@ -79,7 +79,7 @@ Since recursive expansion of macros is not allowed by the C++ preprocessor, replacing the BOOST_PP_REPEAT_2ND above with BOOST_PP_REPEAT, would not produce the above expansion. -See also BOOST_PP_FOR(). +See BOOST_PP_FOR(). */ #define BOOST_PP_REPEAT(N,M,P) BOOST_PP_REPEAT_DELAY(N,M,P) diff --git a/include/boost/preprocessor/tuple.hpp b/include/boost/preprocessor/tuple.hpp index 3f5b22e..4773682 100644 --- a/include/boost/preprocessor/tuple.hpp +++ b/include/boost/preprocessor/tuple.hpp @@ -21,4 +21,5 @@ Includes all tuple headers. #include #include +#include #endif diff --git a/include/boost/preprocessor/tuple/elem.hpp b/include/boost/preprocessor/tuple/elem.hpp index f869bf3..a307cb8 100644 --- a/include/boost/preprocessor/tuple/elem.hpp +++ b/include/boost/preprocessor/tuple/elem.hpp @@ -39,7 +39,7 @@ Examples of tuples: 4-tuple: (A B C, D, EF, 34) \endverbatim -See also BOOST_PP_LIMIT_TUPLE. +See BOOST_PP_LIMIT_TUPLE. */ #define BOOST_PP_TUPLE_ELEM(N,I,T) BOOST_PP_TUPLE_ELEM_DELAY(N,I,T) diff --git a/include/boost/preprocessor/tuple/to_list.hpp b/include/boost/preprocessor/tuple/to_list.hpp new file mode 100644 index 0000000..4d6406e --- /dev/null +++ b/include/boost/preprocessor/tuple/to_list.hpp @@ -0,0 +1,42 @@ +#ifndef BOOST_PREPROCESSOR_TUPLE_TO_LIST_HPP +#define BOOST_PREPROCESSOR_TUPLE_TO_LIST_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +/*! \file + +Click here to see the header. +*/ + +#include + +//! Converts a tuple to a list. +/*! +See BOOST_PP_LIST_CONS() for an example. + +See BOOST_PP_LIMIT_TUPLE. +*/ +#define BOOST_PP_TUPLE_TO_LIST(N,T) BOOST_PP_TUPLE_TO_LIST_DELAY(N,T) + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#define BOOST_PP_TUPLE_TO_LIST_DELAY(N,T) BOOST_PP_TUPLE##N##_TO_LIST T +#define BOOST_PP_TUPLE0_TO_LIST() BOOST_PP_LIST_NIL +#define BOOST_PP_TUPLE1_TO_LIST(A) BOOST_PP_LIST_CONS(A,BOOST_PP_LIST_NIL) +#define BOOST_PP_TUPLE2_TO_LIST(A,B) BOOST_PP_LIST_CONS(A,BOOST_PP_TUPLE1_TO_LIST(B)) +#define BOOST_PP_TUPLE3_TO_LIST(A,B,C) BOOST_PP_LIST_CONS(A,BOOST_PP_TUPLE2_TO_LIST(B,C)) +#define BOOST_PP_TUPLE4_TO_LIST(A,B,C,D) BOOST_PP_LIST_CONS(A,BOOST_PP_TUPLE3_TO_LIST(B,C,D)) +#define BOOST_PP_TUPLE5_TO_LIST(A,B,C,D,E) BOOST_PP_LIST_CONS(A,BOOST_PP_TUPLE4_TO_LIST(B,C,D,E)) +#define BOOST_PP_TUPLE6_TO_LIST(A,B,C,D,E,F) BOOST_PP_LIST_CONS(A,BOOST_PP_TUPLE5_TO_LIST(B,C,D,E,F)) +#define BOOST_PP_TUPLE7_TO_LIST(A,B,C,D,E,F,G) BOOST_PP_LIST_CONS(A,BOOST_PP_TUPLE6_TO_LIST(B,C,D,E,F,G)) +#define BOOST_PP_TUPLE8_TO_LIST(A,B,C,D,E,F,G,H) BOOST_PP_LIST_CONS(A,BOOST_PP_TUPLE7_TO_LIST(B,C,D,E,F,G,H)) +#endif +#endif diff --git a/test/list_test.cpp b/test/list_test.cpp new file mode 100644 index 0000000..2563ff3 --- /dev/null +++ b/test/list_test.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +#include +#include +#include +#include +#include + +#include + +// *** + +#define TEST_LIST BOOST_PP_TUPLE_TO_LIST(5,(4,1,5,9,2)) + +TEST(BOOST_PP_LIST_FOLD_LEFT(BOOST_PP_SUB_D,22,TEST_LIST) == 1) +TEST(BOOST_PP_LIST_CAT(BOOST_PP_LIST_REVERSE(TEST_LIST)) == 29514) +TEST(BOOST_PP_LIST_FOLD_RIGHT(BOOST_PP_SUB_D,TEST_LIST,0) == 3) + +TEST(BOOST_PP_LIST_CAT(BOOST_PP_LIST_REST_N(2,TEST_LIST)) == 592) +TEST(BOOST_PP_LIST_CAT(BOOST_PP_LIST_FIRST_N(2,TEST_LIST)) == 41) + +TEST(BOOST_PP_LIST_AT(TEST_LIST,2) == 5) + +TEST(BOOST_PP_LIST_CAT(BOOST_PP_LIST_TRANSFORM(BOOST_PP_ADD_D,2,TEST_LIST)) == 637114) + +TEST(BOOST_PP_LIST_CAT(BOOST_PP_LIST_APPEND(BOOST_PP_LIST_REST(TEST_LIST),TEST_LIST)) == 159241592) + +#define ENUM_LIST_F(I,P,X) +X+P +TEST(BOOST_PP_LIST_FOR_EACH(ENUM_LIST_F,1,TEST_LIST) == 26) + +TEST(BOOST_PP_TUPLE_ELEM(5,4,BOOST_PP_LIST_TO_TUPLE(TEST_LIST)) == 2) + +TEST(BOOST_PP_LIST_CAT(BOOST_PP_LIST_FILTER(BOOST_PP_LESS_D,3,TEST_LIST)) == 459)