From 3468956bc9812394d3d523471756a1f0d966cea2 Mon Sep 17 00:00:00 2001 From: Vesa Karvonen Date: Thu, 4 Apr 2002 08:23:26 +0000 Subject: [PATCH] Added FROM_TO repetition macros. [SVN r13364] --- doc/keywords.txt | 3 + doc/reference/index.htm | 6 ++ doc/reference/repeat.htm | 2 +- doc/reference/repeat_3rd.htm | 4 +- doc/reference/repeat_from_to.htm | 75 +++++++++++++++++++ doc/reference/repeat_from_to_2nd.htm | 45 +++++++++++ doc/reference/repeat_from_to_3rd.htm | 45 +++++++++++ doc/reference/stringize.htm | 4 +- include/boost/preprocessor.hpp | 6 +- include/boost/preprocessor/repeat.hpp | 2 +- include/boost/preprocessor/repeat_from_to.hpp | 53 +++++++++++++ .../boost/preprocessor/repeat_from_to_2nd.hpp | 23 ++++++ .../boost/preprocessor/repeat_from_to_3rd.hpp | 23 ++++++ test/repeat_test.cpp | 8 ++ 14 files changed, 290 insertions(+), 9 deletions(-) create mode 100644 doc/reference/repeat_from_to.htm create mode 100644 doc/reference/repeat_from_to_2nd.htm create mode 100644 doc/reference/repeat_from_to_3rd.htm create mode 100644 include/boost/preprocessor/repeat_from_to.hpp create mode 100644 include/boost/preprocessor/repeat_from_to_2nd.hpp create mode 100644 include/boost/preprocessor/repeat_from_to_3rd.hpp diff --git a/doc/keywords.txt b/doc/keywords.txt index 211cd4b..eedb1cb 100644 --- a/doc/keywords.txt +++ b/doc/keywords.txt @@ -93,6 +93,9 @@ BOOST_PP_OR BOOST_PP_REPEAT BOOST_PP_REPEAT_2ND BOOST_PP_REPEAT_3RD +BOOST_PP_REPEAT_FROM_TO +BOOST_PP_REPEAT_FROM_TO_2ND +BOOST_PP_REPEAT_FROM_TO_3RD BOOST_PP_STRINGIZE BOOST_PP_SUB BOOST_PP_SUB_D diff --git a/doc/reference/index.htm b/doc/reference/index.htm index 2980348..2ad44cd 100644 --- a/doc/reference/index.htm +++ b/doc/reference/index.htm @@ -116,6 +116,9 @@
BOOST_PP_REPEAT
BOOST_PP_REPEAT_2ND
BOOST_PP_REPEAT_3RD
+
BOOST_PP_REPEAT_FROM_TO
+
BOOST_PP_REPEAT_FROM_TO_2ND
+
BOOST_PP_REPEAT_FROM_TO_3RD
BOOST_PP_STRINGIZE
BOOST_PP_SUB
BOOST_PP_SUB_D
@@ -235,6 +238,9 @@
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/repeat_2nd.hpp>
#include <boost/preprocessor/repeat_3rd.hpp>
+
#include <boost/preprocessor/repeat_from_to.hpp>
+
#include <boost/preprocessor/repeat_from_to_2nd.hpp>
+
#include <boost/preprocessor/repeat_from_to_3rd.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/tuple.hpp>
#include <boost/preprocessor/tuple/eat.hpp>
diff --git a/doc/reference/repeat.htm b/doc/reference/repeat.htm index 24ef886..f506816 100644 --- a/doc/reference/repeat.htm +++ b/doc/reference/repeat.htm @@ -27,7 +27,7 @@

#define BOOST_PP_REPEAT(N,M,P)

-

Repeats the macro M(I,P) for I = [0,N[.

+

Repeats the macro M(I,P) for I = [0,N[.

In other words, expands to the sequence:

diff --git a/doc/reference/repeat_3rd.htm b/doc/reference/repeat_3rd.htm index 87c7239..d100b26 100644 --- a/doc/reference/repeat_3rd.htm +++ b/doc/reference/repeat_3rd.htm @@ -19,7 +19,7 @@
-Prev Next Macros Headers +Prev Next Macros Headers

#include <boost/preprocessor/repeat_3rd.hpp>

@@ -34,7 +34,7 @@

Obsolete. Use BOOST_PP_REPEAT_3RD().


-Prev Next Macros Headers +Prev Next Macros Headers

Revised

diff --git a/doc/reference/repeat_from_to.htm b/doc/reference/repeat_from_to.htm new file mode 100644 index 0000000..b302ad8 --- /dev/null +++ b/doc/reference/repeat_from_to.htm @@ -0,0 +1,75 @@ + + + +Boost.Preprocessor - Reference + + + + + + + +
+

C++ Boost

+
+

Boost.Preprocessor

+

Reference

+
+ +
+ +Prev Next Macros Headers +
+ +

#include <boost/preprocessor/repeat_from_to.hpp>

+ +
+ +

#define BOOST_PP_REPEAT_FROM_TO(S,E,M,P)

+

Repeats the macro M(I,P) for I = [S,E[.

+ +

In other words, expands to the sequence:

+ +
+  M(S,P) M(BOOST_PP_INC(S),P) ... M(BOOST_PP_DEC(E),P)
+
+ +

For example,

+ +
+  #define TEST(I,P) P(I);
+  BOOST_PP_REPEAT_FROM_TO(4,7,TEST,X)
+
+ +

expands to:

+ +
+  X(4); X(5); X(6);
+
+ +

Uses

+ + +

Test

+ + +
+ +Prev Next Macros Headers +
+ +

Revised

+ +

© Copyright Housemarque Oy 2002

+ +

Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +"as is" without express or implied warranty, and with no claim as to its suitability +for any purpose.

+ + diff --git a/doc/reference/repeat_from_to_2nd.htm b/doc/reference/repeat_from_to_2nd.htm new file mode 100644 index 0000000..419c7d6 --- /dev/null +++ b/doc/reference/repeat_from_to_2nd.htm @@ -0,0 +1,45 @@ + + + +Boost.Preprocessor - Reference + + + + + + + +
+

C++ Boost

+
+

Boost.Preprocessor

+

Reference

+
+ +
+ +Prev Next Macros Headers +
+ +

#include <boost/preprocessor/repeat_from_to_2nd.hpp>

+ +
+ +

#define BOOST_PP_REPEAT_FROM_TO_2ND(S,E,M,P)

+

Same as BOOST_PP_REPEAT_FROM_TO(), but implemented independently.

+
+ +Prev Next Macros Headers +
+ +

Revised

+ +

© Copyright Housemarque Oy 2002

+ +

Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +"as is" without express or implied warranty, and with no claim as to its suitability +for any purpose.

+ + diff --git a/doc/reference/repeat_from_to_3rd.htm b/doc/reference/repeat_from_to_3rd.htm new file mode 100644 index 0000000..c168f92 --- /dev/null +++ b/doc/reference/repeat_from_to_3rd.htm @@ -0,0 +1,45 @@ + + + +Boost.Preprocessor - Reference + + + + + + + +
+

C++ Boost

+
+

Boost.Preprocessor

+

Reference

+
+ +
+ +Prev Next Macros Headers +
+ +

#include <boost/preprocessor/repeat_from_to_3rd.hpp>

+ +
+ +

#define BOOST_PP_REPEAT_FROM_TO_3RD(S,E,M,P)

+

Same as BOOST_PP_REPEAT_FROM_TO(), but implemented independently.

+
+ +Prev Next Macros Headers +
+ +

Revised

+ +

© Copyright Housemarque Oy 2002

+ +

Permission to copy, use, modify, sell and distribute this document is granted +provided this copyright notice appears in all copies. This document is provided +"as is" without express or implied warranty, and with no claim as to its suitability +for any purpose.

+ + diff --git a/doc/reference/stringize.htm b/doc/reference/stringize.htm index 8832034..712cd64 100644 --- a/doc/reference/stringize.htm +++ b/doc/reference/stringize.htm @@ -19,7 +19,7 @@
-Prev Next Macros Headers +Prev Next Macros Headers

#include <boost/preprocessor/stringize.hpp>

@@ -47,7 +47,7 @@

Obsolete. Use BOOST_PP_STRINGIZE().


-Prev Next Macros Headers +Prev Next Macros Headers

Revised

diff --git a/include/boost/preprocessor.hpp b/include/boost/preprocessor.hpp index 6618583..cc09742 100644 --- a/include/boost/preprocessor.hpp +++ b/include/boost/preprocessor.hpp @@ -29,8 +29,8 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #endif diff --git a/include/boost/preprocessor/repeat.hpp b/include/boost/preprocessor/repeat.hpp index d610054..439483f 100644 --- a/include/boost/preprocessor/repeat.hpp +++ b/include/boost/preprocessor/repeat.hpp @@ -13,7 +13,7 @@ * See http://www.boost.org for most recent version. */ -/**

Repeats the macro M(I,P) for I = [0,N[.

+/**

Repeats the macro M(I,P) for I = [0,N[.

In other words, expands to the sequence:

diff --git a/include/boost/preprocessor/repeat_from_to.hpp b/include/boost/preprocessor/repeat_from_to.hpp new file mode 100644 index 0000000..00ec641 --- /dev/null +++ b/include/boost/preprocessor/repeat_from_to.hpp @@ -0,0 +1,53 @@ +#ifndef BOOST_PREPROCESSOR_REPEAT_FROM_TO_HPP +#define BOOST_PREPROCESSOR_REPEAT_FROM_TO_HPP + +/* Copyright (C) 2002 + * 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 + +/**

Repeats the macro M(I,P) for I = [S,E[.

+ +

In other words, expands to the sequence:

+ +
+  M(S,P) M(BOOST_PP_INC(S),P) ... M(BOOST_PP_DEC(E),P)
+
+ +

For example,

+ +
+  #define TEST(I,P) P(I);
+  BOOST_PP_REPEAT_FROM_TO(4,7,TEST,X)
+
+ +

expands to:

+ +
+  X(4); X(5); X(6);
+
+ +

Uses

+
    +
  • BOOST_PP_REPEAT()
  • +
+ +

Test

+ +*/ +#define BOOST_PP_REPEAT_FROM_TO(S,E,M,P) BOOST_PP_REPEAT(BOOST_PP_SUB(E,S),BOOST_PP_REPEAT_FROM_TO_F,(S,M,P)) +#define BOOST_PP_REPEAT_FROM_TO_F(I,SMP) BOOST_PP_TUPLE_ELEM(3,1,SMP)(BOOST_PP_ADD(I,BOOST_PP_TUPLE_ELEM(3,0,SMP)),BOOST_PP_TUPLE_ELEM(3,2,SMP)) +#endif diff --git a/include/boost/preprocessor/repeat_from_to_2nd.hpp b/include/boost/preprocessor/repeat_from_to_2nd.hpp new file mode 100644 index 0000000..32f707a --- /dev/null +++ b/include/boost/preprocessor/repeat_from_to_2nd.hpp @@ -0,0 +1,23 @@ +#ifndef BOOST_PREPROCESSOR_REPEAT_FROM_TO_2ND_HPP +#define BOOST_PREPROCESSOR_REPEAT_FROM_TO_2ND_HPP + +/* Copyright (C) 2002 + * 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 + +/**

Same as BOOST_PP_REPEAT_FROM_TO(), but implemented independently.

*/ +#define BOOST_PP_REPEAT_FROM_TO_2ND(S,E,M,P) BOOST_PP_REPEAT_2ND(BOOST_PP_SUB(E,S),BOOST_PP_REPEAT_FROM_TO_2ND_F,(S,M,P)) +#define BOOST_PP_REPEAT_FROM_TO_2ND_F(I,SMP) BOOST_PP_TUPLE_ELEM(3,1,SMP)(BOOST_PP_ADD(I,BOOST_PP_TUPLE_ELEM(3,0,SMP)),BOOST_PP_TUPLE_ELEM(3,2,SMP)) +#endif diff --git a/include/boost/preprocessor/repeat_from_to_3rd.hpp b/include/boost/preprocessor/repeat_from_to_3rd.hpp new file mode 100644 index 0000000..cf5a0ac --- /dev/null +++ b/include/boost/preprocessor/repeat_from_to_3rd.hpp @@ -0,0 +1,23 @@ +#ifndef BOOST_PREPROCESSOR_REPEAT_FROM_TO_3RD_HPP +#define BOOST_PREPROCESSOR_REPEAT_FROM_TO_3RD_HPP + +/* Copyright (C) 2002 + * 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 + +/**

Same as BOOST_PP_REPEAT_FROM_TO(), but implemented independently.

*/ +#define BOOST_PP_REPEAT_FROM_TO_3RD(S,E,M,P) BOOST_PP_REPEAT_3RD(BOOST_PP_SUB(E,S),BOOST_PP_REPEAT_FROM_TO_3RD_F,(S,M,P)) +#define BOOST_PP_REPEAT_FROM_TO_3RD_F(I,SMP) BOOST_PP_TUPLE_ELEM(3,1,SMP)(BOOST_PP_ADD(I,BOOST_PP_TUPLE_ELEM(3,0,SMP)),BOOST_PP_TUPLE_ELEM(3,2,SMP)) +#endif diff --git a/test/repeat_test.cpp b/test/repeat_test.cpp index 99e56ea..6de24f2 100644 --- a/test/repeat_test.cpp +++ b/test/repeat_test.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include /* *** */ @@ -46,3 +48,9 @@ TEST_ENUM_PARAMS(ENUM_PARAMS_TEST_MAX) template struct no_rescan; + +/* *** */ + +#define F(I,P) P I +TEST_B 1 + (4+5+6) BOOST_PP_REPEAT_FROM_TO(4,7,F,-) TEST_E +#undef F