forked from boostorg/preprocessor
Working on docs.
[SVN r12587]
This commit is contained in:
50
example/catch_builtin.cpp
Normal file
50
example/catch_builtin.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/* This example demonstrates the usage of lists and BOOST_PP_LIST_FOR_EACH(). */
|
||||
|
||||
#include <boost/preprocessor/list/for_each.hpp>
|
||||
#include <boost/preprocessor/tuple/to_list.hpp>
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
/* List of built-in types. (Strictly speaking wchar_t should be on the list.) */
|
||||
#define BUILTIN_TYPES\
|
||||
BOOST_PP_TUPLE_TO_LIST\
|
||||
( 13\
|
||||
, ( bool\
|
||||
, char\
|
||||
, signed char\
|
||||
, unsigned char\
|
||||
, unsigned short\
|
||||
, short\
|
||||
, int\
|
||||
, unsigned\
|
||||
, long\
|
||||
, unsigned long\
|
||||
, float\
|
||||
, double\
|
||||
, long double\
|
||||
)\
|
||||
)
|
||||
|
||||
/* This is the macro we pass to BOOST_PP_LIST_FOR_EACH(). */
|
||||
#define CATCH(R,_,T)\
|
||||
catch (T t) { std::cerr << "Caught an " << typeid(t).name() << " = " << t; }
|
||||
|
||||
int main()
|
||||
{
|
||||
try { throw 10; }
|
||||
BOOST_PP_LIST_FOR_EACH(CATCH,_,BUILTIN_TYPES)
|
||||
|
||||
return 0;
|
||||
}
|
30
example/count_down.c
Normal file
30
example/count_down.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/* This is a trivial example of using BOOST_PP_WHILE() that simply
|
||||
* counts down from N to 0 ultimately expanding to a 0.
|
||||
*/
|
||||
|
||||
#include <boost/preprocessor/dec.hpp>
|
||||
#include <boost/preprocessor/while.hpp>
|
||||
|
||||
#define COUNT_DOWN(N) BOOST_PP_WHILE(COUNT_DOWN_C,COUNT_DOWN_F,N)
|
||||
/* Above is the macro we are implementing using BOOST_PP_WHILE(). */
|
||||
|
||||
#define COUNT_DOWN_C(D,N) N
|
||||
/* Above is the condition. It expands to the current N. */
|
||||
|
||||
#define COUNT_DOWN_F(D,N) BOOST_PP_DEC(N)
|
||||
/* Above is the iteration macro. It decrements N. */
|
||||
|
||||
enum { x = COUNT_DOWN(50) };
|
||||
/* The above expands to 0. */
|
74
example/repeat_2d.c
Normal file
74
example/repeat_2d.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/* This example implements a generalized macro for 2D repetition using
|
||||
* the simple repetition primitives of the preprocessor library.
|
||||
*/
|
||||
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/repeat_2nd.hpp>
|
||||
|
||||
/** Repeats the macro M(X,Y,P) for X = [0,W[ and Y = [0,H[.
|
||||
|
||||
In other words, expands to the sequence:
|
||||
|
||||
<PRE>\verbatim
|
||||
M( 0, 0, P) M( 1, 0, P) ... M(W-1, 0, P)
|
||||
M( 0, 1, P) M( 1, 1, P) ... M(W-1, 1, P)
|
||||
... ... ... ...
|
||||
M( 0,H-1, P) M( 1,H-1, P) ... M(W-1,H-1, P)
|
||||
\endverbatim</PRE>
|
||||
|
||||
Uses BOOST_PP_REPEAT() and BOOST_PP_REPEAT_2ND().
|
||||
*/
|
||||
#define REPEAT_2D(W,H,M,P)\
|
||||
/* Here we must use BOOST_PP_REPEAT_2ND(), because\
|
||||
* we use BOOST_PP_REPEAT() in REPEAT_2D_ROW().\
|
||||
*/\
|
||||
BOOST_PP_REPEAT_2ND\
|
||||
( H\
|
||||
, REPEAT_2D_ROW\
|
||||
, (W,M,P)\
|
||||
)
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
#define REPEAT_2D_ROW(Y,WMP)\
|
||||
BOOST_PP_REPEAT\
|
||||
( BOOST_PP_TUPLE_ELEM(3,0,WMP)\
|
||||
, REPEAT_2D_ELEM\
|
||||
, (Y, BOOST_PP_TUPLE_ELEM(3,1,WMP), BOOST_PP_TUPLE_ELEM(3,2,WMP))\
|
||||
)
|
||||
#define REPEAT_2D_ELEM(X,YMP)\
|
||||
BOOST_PP_TUPLE_ELEM(3,1,YMP)\
|
||||
( X\
|
||||
, BOOST_PP_TUPLE_ELEM(3,0,YMP)\
|
||||
, BOOST_PP_TUPLE_ELEM(3,2,YMP)\
|
||||
)
|
||||
#endif
|
||||
|
||||
#include <boost/preprocessor/logical/or.hpp>
|
||||
#include <boost/preprocessor/comma_if.hpp>
|
||||
#include <boost/preprocessor/list/cat.hpp>
|
||||
#include <boost/preprocessor/tuple/to_list.hpp>
|
||||
|
||||
/* Here we use the above macro to generate something. */
|
||||
#define ELEM(X,Y,E) BOOST_PP_COMMA_IF(BOOST_PP_OR(X,Y)) BOOST_PP_LIST_CAT(BOOST_PP_TUPLE_TO_LIST(5,(E,_,X,_,Y)))
|
||||
|
||||
enum { REPEAT_2D(3,4,ELEM,elem) };
|
||||
|
||||
/* The above expands to:
|
||||
*
|
||||
* enum { elem_0_0, elem_1_0, elem_2_0,
|
||||
* elem_0_1, elem_1_1, elem_2_1,
|
||||
* elem_0_2, elem_1_2, elem_2_2,
|
||||
* elem_0_3, elem_1_3, elem_2_3 };
|
||||
*/
|
Reference in New Issue
Block a user