From 3b7418f9cea9cd56b14d511102cda9de9e1542b8 Mon Sep 17 00:00:00 2001
From: Vesa Karvonen Delays the catenation of X and Y. Catenates X and Y after they are macro expanded. For example, expands to: Using BOOST_PP_CAT() above lets the PP expand the __LINE__. If the above
-code would use the ## operator directly then __LINE__ would not be expanded and
-the above would expand to: BOOST_PP_FOR() is a generalization of BOOST_PP_REPEAT(). This means that
-BOOST_PP_REPEAT() can be implemented using BOOST_PP_FOR(). Unfortunately,
-BOOST_PP_FOR() is slower than BOOST_PP_REPEAT(). In addition,
+BOOST_PP_REPEAT() can be implemented using BOOST_PP_FOR(). However,
BOOST_PP_REPEAT() was introduced earlier, is generally easier to use, and is
still quite useful on its own.
#define BOOST_PP_CAT(X,Y)
-
- #define STATIC_ASSERT(EXPR)\
- enum\
- { BOOST_PP_CAT(static_check_,__LINE__) = (EXPR) ? 1 : -1\
- };\
- typedef char\
- BOOST_PP_CAT(static_assert_,__LINE__)\
- [ BOOST_PP_CAT(static_check_,__LINE__)\
- ]
-
- // ...
-
- STATIC_ASSERT(sizeof(int) <= sizeof(long));
-
-
-
- enum
- { static_check_152 = (sizeof(int) <= sizeof(long)) ? 1 : -1
- };
- typedef char
- static_assert_152
- [ static_check_152
- ];
-
-
-
- enum
- { static_check___LINE__ = (sizeof(int) <= sizeof(long)) ? 1 : -1
- };
- typedef char
- static_assert___LINE__
- [ static_check___LINE__
- ];
-
+Example
+
+
diff --git a/doc/reference/for.htm b/doc/reference/for.htm
index 46364b1..bb08b62 100644
--- a/doc/reference/for.htm
+++ b/doc/reference/for.htm
@@ -39,8 +39,7 @@
BOOST_PP_REPEAT() vs BOOST_PP_FOR()
NOTE: If BOOST_PP_IDENTITY() is not invoked, the expansion will not be -usable.
+BOOST_PP_IDENTITY() needs to be invoked.
This is also the limit of the repetition primitives (BOOST_PP_ENUM family and BOOST_PP_REPEAT family).
-NOTES:
+Note that folding, or accumulation, is a very general pattern of computation. +
Folding, or accumulation, is a very general pattern of computation. Most list operations can be implemented in terms of folding.
expands to (A,B,C).
-NOTE: The supported size of the list being converted to a tuple is limited by +
The supported size of the list being converted to a tuple is limited by BOOST_PP_LIMIT_MAG rather than BOOST_PP_LIMIT_TUPLE.
Delays the stringization of X.
+Stringizes X after it is macro expanded.
-For example,
- -- #define NOTE(STR)\ - message(__FILE__ "(" BOOST_PP_STRINGIZE(__LINE__) ") : " STR) - - // ... - - #pragma NOTE("TBD!") -- -
expands to:
- -- #pragma message("examples.cpp" "(" "20" ") : " "TBD!") -- -
The use of BOOST_PP_STRINGIZE() above lets the PP expand the __LINE__ -before stringizing it. If # would be used directly, the code would -expand to:
- -- #pragma message("examples.cpp" "(" "__LINE__" ") : " "TBD!") -+
Converts a tuple to a list.
+For example,
+ ++ BOOST_PP_TUPLE_TO_LIST(3,(A,B,C)) ++ +
expands to the same as
+ ++ BOOST_PP_LIST_CONS(A, + BOOST_PP_LIST_CONS(B, + BOOST_PP_LIST_CONS(C, + BOOST_PP_LIST_NIL))) ++
NOTE: The value of the D parameter may exceed BOOST_PP_LIMIT_MAG.
- -Using BOOST_PP_WHILE() is a bit tricky. This is due to the C++ preprocessor limitations. It is recommended to take a look at the implementations of the -various PREPROCESSOR library primitives such as BOOST_PP_ADD() for additional -examples.
+various PREPROCESSOR library primitives such as BOOST_PP_ADD() for +additional examples.For a more complex example, let's take a look at an implementation of -BOOST_PP_MUL().
- -- #define BOOST_PP_MUL(X,Y) BOOST_PP_MUL_D(0,X,Y) - // Since the macro is implemented using WHILE, the actual implementation - // takes a depth as a parameter so that it can be called inside a WHILE. - // The above easy-to-use version simply uses 0 as the depth and can not be - // called inside a WHILE. - - #define BOOST_PP_MUL_D(D,X,Y)\ - BOOST_PP_TUPLE_ELEM(3,0,BOOST_PP_WHILE##D(BOOST_PP_MUL_C,BOOST_PP_MUL_F,(0,X,Y))) - // ^^^ ^^^ ^^ ^^ ^^^^^^^ - // #1 #2 #3 #3 #1 - // - // #1) The state is a 3-tuple. After the iteration is finished, the first - // element of the tuple is the result. - // - // #2) The WHILE primitive is "invoked" directly. BOOST_PP_WHILE(D,...) - // can't be used because it would not be expanded by the C++ preprocessor. - // - // #3) ???_C is the condition and ???_F is the iteration macro. - - #define BOOST_PP_MUL_C(D,P)\ - BOOST_PP_TUPLE_ELEM(3,2,P) - // Iteration is finished when the counter reaches 0. - - #define BOOST_PP_MUL_F(D,P)\ - ( BOOST_PP_ADD_D(D,BOOST_PP_TUPLE_ELEM(3,0,P),BOOST_PP_TUPLE_ELEM(3,1,P))\ - , BOOST_PP_TUPLE_ELEM(3,1,P)\ - , BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(3,2,P))\ - ) - // ( The result is increased by the multiplier. - // , The multiplier is retained without change. - // , The counter is decreased. - // ) --
EXAMPLE: - Use BOOST_PP_EMPTY() as an unused parameter in Local Macro instantiations
+ Use BOOST_PP_EMPTY as an unused parameter in Local Macro instantiations#define BOOST_PP_DEF(CV) \ template<class base> \ - CV typename implement_subscript_using_begin_subscript<base>::value_type&\ + CV() typename implement_subscript_using_begin_subscript<base>::value_type&\ implement_subscript_using_begin_subscript<base>::operator[]\ ( index_type \ i \ - ) CV \ + ) CV() \ { return base::begin()[i];\ } -BOOST_PP_DEF(BOOST_PP_EMPTY()) -BOOST_PP_DEF(const) +BOOST_PP_DEF(BOOST_PP_EMPTY) +BOOST_PP_DEF(const BOOST_PP_EMPTY) #undef BOOST_PP_DEF