mirror of
https://github.com/boostorg/preprocessor.git
synced 2025-07-15 21:42:08 +02:00
LIST_FOR_EACH_PRODUCT() added to library
[SVN r12571]
This commit is contained in:
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libs/preprocessor/example/array_arithmetic_helpers.hpp>
|
#include <libs/preprocessor/example/array_arithmetic_helpers.hpp>
|
||||||
|
#include <boost/preprocessor/list/for_each_product.hpp>
|
||||||
#include <boost/preprocessor/list/at.hpp>
|
#include <boost/preprocessor/list/at.hpp>
|
||||||
#include <boost/preprocessor/list/append.hpp>
|
#include <boost/preprocessor/list/append.hpp>
|
||||||
#include <boost/preprocessor/tuple/to_list.hpp>
|
#include <boost/preprocessor/tuple/to_list.hpp>
|
||||||
@ -116,7 +117,7 @@
|
|||||||
#define IS_VALID_BINARY_OP_AND_TYPE_COMBINATION(O,L,R) BOOST_PP_IF(BOOST_PP_OR(TYPE_IS_FLOATING(L),TYPE_IS_FLOATING(R)),OP_IS_FLOATING(O),1)
|
#define IS_VALID_BINARY_OP_AND_TYPE_COMBINATION(O,L,R) BOOST_PP_IF(BOOST_PP_OR(TYPE_IS_FLOATING(L),TYPE_IS_FLOATING(R)),OP_IS_FLOATING(O),1)
|
||||||
|
|
||||||
/* Generates code for all all unary operators and integral types. */
|
/* Generates code for all all unary operators and integral types. */
|
||||||
#define UNARY_ARRAY_OP(_,L) UNARY_ARRAY_OP2(BOOST_PP_LIST_AT(L,1),BOOST_PP_LIST_FIRST(L))
|
#define UNARY_ARRAY_OP(R,_,L) UNARY_ARRAY_OP2(BOOST_PP_LIST_AT(L,1),BOOST_PP_LIST_FIRST(L))
|
||||||
#define UNARY_ARRAY_OP2(O,T) BOOST_PP_IF(IS_VALID_UNARY_OP_AND_TYPE_COMBINATION(O,T),UNARY_ARRAY_OP3,BOOST_PP_TUPLE2_EAT)(O,T)
|
#define UNARY_ARRAY_OP2(O,T) BOOST_PP_IF(IS_VALID_UNARY_OP_AND_TYPE_COMBINATION(O,T),UNARY_ARRAY_OP3,BOOST_PP_TUPLE2_EAT)(O,T)
|
||||||
#define UNARY_ARRAY_OP3(O,T)\
|
#define UNARY_ARRAY_OP3(O,T)\
|
||||||
void BOOST_PP_CAT4(array_,OP_NAME(O),_,TYPE_ABBREVIATION(T))\
|
void BOOST_PP_CAT4(array_,OP_NAME(O),_,TYPE_ABBREVIATION(T))\
|
||||||
@ -126,7 +127,7 @@
|
|||||||
BOOST_PP_LIST_FOR_EACH_PRODUCT(UNARY_ARRAY_OP,_,BOOST_PP_TUPLE_TO_LIST(2,(APPLICATIVE_UNARY_OPS,BUILTIN_TYPES)))
|
BOOST_PP_LIST_FOR_EACH_PRODUCT(UNARY_ARRAY_OP,_,BOOST_PP_TUPLE_TO_LIST(2,(APPLICATIVE_UNARY_OPS,BUILTIN_TYPES)))
|
||||||
|
|
||||||
/* Generates code for all binary operators and integral type pairs. */
|
/* Generates code for all binary operators and integral type pairs. */
|
||||||
#define BINARY_ARRAY_OP(_,L) BINARY_ARRAY_OP2(BOOST_PP_LIST_AT(L,2),BOOST_PP_LIST_AT(L,1),BOOST_PP_LIST_FIRST(L))
|
#define BINARY_ARRAY_OP(R,_,L) BINARY_ARRAY_OP2(BOOST_PP_LIST_AT(L,2),BOOST_PP_LIST_AT(L,1),BOOST_PP_LIST_FIRST(L))
|
||||||
#define BINARY_ARRAY_OP2(O,L,R) BOOST_PP_IF(IS_VALID_BINARY_OP_AND_TYPE_COMBINATION(O,L,R),BINARY_ARRAY_OP3,BOOST_PP_TUPLE3_EAT)(O,L,R)
|
#define BINARY_ARRAY_OP2(O,L,R) BOOST_PP_IF(IS_VALID_BINARY_OP_AND_TYPE_COMBINATION(O,L,R),BINARY_ARRAY_OP3,BOOST_PP_TUPLE3_EAT)(O,L,R)
|
||||||
#define BINARY_ARRAY_OP3(O,L,R)\
|
#define BINARY_ARRAY_OP3(O,L,R)\
|
||||||
void BOOST_PP_CAT6(array_,OP_NAME(O),_,TYPE_ABBREVIATION(L),_,TYPE_ABBREVIATION(R))\
|
void BOOST_PP_CAT6(array_,OP_NAME(O),_,TYPE_ABBREVIATION(L),_,TYPE_ABBREVIATION(R))\
|
||||||
|
@ -13,80 +13,10 @@
|
|||||||
* See http://www.boost.org for most recent version.
|
* See http://www.boost.org for most recent version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/preprocessor/list/adt.hpp>
|
|
||||||
#include <boost/preprocessor/for.hpp>
|
|
||||||
#include <boost/preprocessor/cat.hpp>
|
#include <boost/preprocessor/cat.hpp>
|
||||||
|
|
||||||
#define BOOST_PP_CAT3(A,B,C) BOOST_PP_CAT(BOOST_PP_CAT(A,B),C)
|
#define BOOST_PP_CAT3(A,B,C) BOOST_PP_CAT(BOOST_PP_CAT(A,B),C)
|
||||||
#define BOOST_PP_CAT4(A,B,C,D) BOOST_PP_CAT3(BOOST_PP_CAT(A,B),C,D)
|
#define BOOST_PP_CAT4(A,B,C,D) BOOST_PP_CAT3(BOOST_PP_CAT(A,B),C,D)
|
||||||
#define BOOST_PP_CAT5(A,B,C,D,E) BOOST_PP_CAT4(BOOST_PP_CAT(A,B),C,D,E)
|
#define BOOST_PP_CAT5(A,B,C,D,E) BOOST_PP_CAT4(BOOST_PP_CAT(A,B),C,D,E)
|
||||||
#define BOOST_PP_CAT6(A,B,C,D,E,F) BOOST_PP_CAT5(BOOST_PP_CAT(A,B),C,D,E,F)
|
#define BOOST_PP_CAT6(A,B,C,D,E,F) BOOST_PP_CAT5(BOOST_PP_CAT(A,B),C,D,E,F)
|
||||||
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT(F,P,LL) BOOST_PP_LIST_FOR_EACH_PRODUCT_R(0,F,P,LL)
|
|
||||||
|
|
||||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_R(R,F,P,LL)\
|
|
||||||
BOOST_PP_FOR##R\
|
|
||||||
( (BOOST_PP_TUPLE3_ELEM0 LL,BOOST_PP_TUPLE3_ELEM1 LL,(_,_,0),F,P)\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_C\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_F\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I0\
|
|
||||||
)
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_C(R,P)\
|
|
||||||
BOOST_PP_TUPLE3_ELEM2 BOOST_PP_TUPLE5_ELEM0 P
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_F(R,P)\
|
|
||||||
( BOOST_PP_LIST_REST(BOOST_PP_TUPLE5_ELEM0 P)\
|
|
||||||
, BOOST_PP_TUPLE5_ELEM1 P\
|
|
||||||
, BOOST_PP_TUPLE5_ELEM2 P\
|
|
||||||
, BOOST_PP_TUPLE5_ELEM3 P\
|
|
||||||
, BOOST_PP_TUPLE5_ELEM4 P\
|
|
||||||
)
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_I_HELPER(P,C,F,I)\
|
|
||||||
BOOST_PP_TUPLE5_ELEM3 P(BOOST_PP_TUPLE5_ELEM4 P,BOOST_PP_TUPLE5_ELEM2 P)
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_I0(R,P)\
|
|
||||||
BOOST_PP_IF\
|
|
||||||
( BOOST_PP_TUPLE3_ELEM2 BOOST_PP_TUPLE5_ELEM1 P\
|
|
||||||
, BOOST_PP_FOR##R\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I_HELPER\
|
|
||||||
)\
|
|
||||||
( (BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM1 P,BOOST_PP_TUPLE3_ELEM1 BOOST_PP_TUPLE5_ELEM1 P,(BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM0 P,BOOST_PP_TUPLE5_ELEM2 P,1),BOOST_PP_TUPLE5_ELEM3 P,BOOST_PP_TUPLE5_ELEM4 P)\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_C\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_F\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I##1\
|
|
||||||
)
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_I1(R,P)\
|
|
||||||
BOOST_PP_IF\
|
|
||||||
( BOOST_PP_TUPLE3_ELEM2 BOOST_PP_TUPLE5_ELEM1 P\
|
|
||||||
, BOOST_PP_FOR##R\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I_HELPER\
|
|
||||||
)\
|
|
||||||
( (BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM1 P,BOOST_PP_TUPLE3_ELEM1 BOOST_PP_TUPLE5_ELEM1 P,(BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM0 P,BOOST_PP_TUPLE5_ELEM2 P,1),BOOST_PP_TUPLE5_ELEM3 P,BOOST_PP_TUPLE5_ELEM4 P)\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_C\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_F\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I##2\
|
|
||||||
)
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_I2(R,P)\
|
|
||||||
BOOST_PP_IF\
|
|
||||||
( BOOST_PP_TUPLE3_ELEM2 BOOST_PP_TUPLE5_ELEM1 P\
|
|
||||||
, BOOST_PP_FOR##R\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I_HELPER\
|
|
||||||
)\
|
|
||||||
( (BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM1 P,BOOST_PP_TUPLE3_ELEM1 BOOST_PP_TUPLE5_ELEM1 P,(BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM0 P,BOOST_PP_TUPLE5_ELEM2 P,1),BOOST_PP_TUPLE5_ELEM3 P,BOOST_PP_TUPLE5_ELEM4 P)\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_C\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_F\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I##3\
|
|
||||||
)
|
|
||||||
#define BOOST_PP_LIST_FOR_EACH_PRODUCT_I3(R,P)\
|
|
||||||
BOOST_PP_IF\
|
|
||||||
( BOOST_PP_TUPLE3_ELEM2 BOOST_PP_TUPLE5_ELEM1 P\
|
|
||||||
, BOOST_PP_FOR##R\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I_HELPER\
|
|
||||||
)\
|
|
||||||
( (BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM1 P,BOOST_PP_TUPLE3_ELEM1 BOOST_PP_TUPLE5_ELEM1 P,(BOOST_PP_TUPLE3_ELEM0 BOOST_PP_TUPLE5_ELEM0 P,BOOST_PP_TUPLE5_ELEM2 P,1),BOOST_PP_TUPLE5_ELEM3 P,BOOST_PP_TUPLE5_ELEM4 P)\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_C\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_F\
|
|
||||||
, BOOST_PP_LIST_FOR_EACH_PRODUCT_I##4\
|
|
||||||
)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
|
|
||||||
/* This example demonstrates the usage of preprocessor lists for generating C++ code. */
|
/* This example demonstrates the usage of preprocessor lists for generating C++ code. */
|
||||||
|
|
||||||
#include <boost/preprocessor/list/for_each.hpp>
|
#include <boost/preprocessor/list/for_each_product.hpp>
|
||||||
|
#include <boost/preprocessor/list/at.hpp>
|
||||||
#include <boost/preprocessor/tuple/to_list.hpp>
|
#include <boost/preprocessor/tuple/to_list.hpp>
|
||||||
#include <boost/preprocessor/empty.hpp>
|
#include <boost/preprocessor/empty.hpp>
|
||||||
|
|
||||||
@ -20,18 +21,18 @@
|
|||||||
#define INTEGRAL_TYPES\
|
#define INTEGRAL_TYPES\
|
||||||
BOOST_PP_TUPLE_TO_LIST(9,(char, signed char, unsigned char, short, unsigned short, int, unsigned, long, unsigned long))
|
BOOST_PP_TUPLE_TO_LIST(9,(char, signed char, unsigned char, short, unsigned short, int, unsigned, long, unsigned long))
|
||||||
|
|
||||||
|
/* List of invokeable cv-qualifiers. */
|
||||||
|
#define CV_QUALIFIERS\
|
||||||
|
BOOST_PP_TUPLE_TO_LIST(4,(BOOST_PP_EMPTY, const BOOST_PP_EMPTY, volatile BOOST_PP_EMPTY, const volatile BOOST_PP_EMPTY))
|
||||||
|
|
||||||
/* Template for testing whether a type is an integral type. */
|
/* Template for testing whether a type is an integral type. */
|
||||||
template<class T> struct is_integral {enum {value = false};};
|
template<class T> struct is_integral {enum {value = false};};
|
||||||
|
|
||||||
/* Macro for defining a specialization of is_integral<> template.
|
/* Macro for defining a specialization of is_integral<> template. */
|
||||||
* NOTE: CV is invoked so that it is possible to pass empty cv-qualifiers.
|
#define IS_INTEGRAL_SPECIALIZATION(R,_,L)\
|
||||||
*/
|
template<> struct is_integral<BOOST_PP_LIST_AT(L,1)() BOOST_PP_LIST_AT(L,0)> {enum {value = true};};
|
||||||
#define IS_INTEGRAL_SPECIALIZATION(_,CV,T)\
|
|
||||||
template<> struct is_integral<CV() T> {enum {value = true};};
|
|
||||||
|
|
||||||
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, BOOST_PP_EMPTY, INTEGRAL_TYPES)
|
BOOST_PP_LIST_FOR_EACH_PRODUCT(IS_INTEGRAL_SPECIALIZATION,_,BOOST_PP_TUPLE_TO_LIST(2,(CV_QUALIFIERS, INTEGRAL_TYPES)))
|
||||||
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, const BOOST_PP_EMPTY, INTEGRAL_TYPES)
|
|
||||||
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, volatile BOOST_PP_EMPTY, INTEGRAL_TYPES)
|
|
||||||
BOOST_PP_LIST_FOR_EACH(IS_INTEGRAL_SPECIALIZATION, const volatile BOOST_PP_EMPTY, INTEGRAL_TYPES)
|
|
||||||
#undef IS_INTEGRAL_SPECIALIZATION
|
#undef IS_INTEGRAL_SPECIALIZATION
|
||||||
|
#undef CV_QUALIFIERS
|
||||||
#undef INTEGRAL_TYPES
|
#undef INTEGRAL_TYPES
|
||||||
|
Reference in New Issue
Block a user