From 3b7418f9cea9cd56b14d511102cda9de9e1542b8 Mon Sep 17 00:00:00 2001 From: Vesa Karvonen Date: Thu, 31 Jan 2002 21:52:46 +0000 Subject: [PATCH] Working on docs [SVN r12612] --- doc/reference/cat.htm | 48 ++++-------------------------- doc/reference/for.htm | 3 +- doc/reference/identity.htm | 5 ++-- doc/reference/limits.htm | 5 ++-- doc/reference/list_fold_left.htm | 4 ++- doc/reference/list_to_tuple.htm | 4 ++- doc/reference/stringize.htm | 30 ++++--------------- doc/reference/tuple_to_list.htm | 16 +++++++++- doc/reference/while.htm | 50 ++++---------------------------- doc/tutorial.htm | 14 ++++----- 10 files changed, 51 insertions(+), 128 deletions(-) diff --git a/doc/reference/cat.htm b/doc/reference/cat.htm index 0ef0cba..13822c7 100644 --- a/doc/reference/cat.htm +++ b/doc/reference/cat.htm @@ -9,50 +9,12 @@

#define BOOST_PP_CAT(X,Y)

-

Delays the catenation of X and Y.

+

Catenates X and Y after they are macro expanded.

-

For example,

- -
-  #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));
-
- -

expands to:

- -
-  enum
-  { static_check_152 = (sizeof(int) <= sizeof(long)) ? 1 : -1
-  };
-  typedef char
-    static_assert_152
-    [ static_check_152
-    ];
-
- -

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:

- -
-  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()

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.

diff --git a/doc/reference/identity.htm b/doc/reference/identity.htm index d0450e4..41510dd 100644 --- a/doc/reference/identity.htm +++ b/doc/reference/identity.htm @@ -26,8 +26,9 @@ invoked.

X -

NOTE: If BOOST_PP_IDENTITY() is not invoked, the expansion will not be -usable.

+

Note

+ +

BOOST_PP_IDENTITY() needs to be invoked.


diff --git a/doc/reference/limits.htm b/doc/reference/limits.htm index 7543baa..bfddea3 100644 --- a/doc/reference/limits.htm +++ b/doc/reference/limits.htm @@ -24,11 +24,12 @@ library.

This is also the limit of the repetition primitives (BOOST_PP_ENUM family and BOOST_PP_REPEAT family).

-

NOTES:

+

Note

diff --git a/doc/reference/list_fold_left.htm b/doc/reference/list_fold_left.htm index 7f6a5ad..096d1ab 100644 --- a/doc/reference/list_fold_left.htm +++ b/doc/reference/list_fold_left.htm @@ -27,7 +27,9 @@ ) -

Note that folding, or accumulation, is a very general pattern of computation. +

Note

+ +

Folding, or accumulation, is a very general pattern of computation. Most list operations can be implemented in terms of folding.

See

diff --git a/doc/reference/list_to_tuple.htm b/doc/reference/list_to_tuple.htm index 988bf1b..c2fcab9 100644 --- a/doc/reference/list_to_tuple.htm +++ b/doc/reference/list_to_tuple.htm @@ -19,7 +19,9 @@

expands to (A,B,C).

-

NOTE: The supported size of the list being converted to a tuple is limited by +

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.

Uses

diff --git a/doc/reference/stringize.htm b/doc/reference/stringize.htm index 0a5de1b..10156a1 100644 --- a/doc/reference/stringize.htm +++ b/doc/reference/stringize.htm @@ -9,32 +9,12 @@

#define BOOST_PP_STRINGIZE(X)

-

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!")
-
+

Example

+
diff --git a/doc/reference/tuple_to_list.htm b/doc/reference/tuple_to_list.htm index 64d3f54..acae424 100644 --- a/doc/reference/tuple_to_list.htm +++ b/doc/reference/tuple_to_list.htm @@ -11,9 +11,23 @@

#define BOOST_PP_TUPLE_TO_LIST(N,T)

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)))
+
+

See

diff --git a/doc/reference/while.htm b/doc/reference/while.htm index dec42cd..42ae58a 100644 --- a/doc/reference/while.htm +++ b/doc/reference/while.htm @@ -33,61 +33,23 @@ D suffix (e.g. BOOST_PP_ADD_D()), that accepts an additional recursion depth as the first parameter. This technique is necessary to avoid recursively expanding the same macro again, which is not permitted by the - C++ preprocessor. + C++ preprocessor. Note that the value of the D parameter may exceed + BOOST_PP_LIMIT_MAG. -

NOTE: The value of the D parameter may exceed BOOST_PP_LIMIT_MAG.

- -

Caveat

+

Note

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.

Example

-

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.
-  // )
-
-

Implementation rationale