コード例 #1
0
ファイル: preprocessorUtils.cpp プロジェクト: JT-a/USD
#include <boost/preprocessor/punctuation/paren.hpp>
#include <boost/preprocessor/tuple/eat.hpp>

#define _MAX_ARGS 64

/* Python code for generating The TF_ARG_N() macros:
for i in range(1, 32+1):
    line = '#define TF_ARG_%d(' % i
    for j in range(1, i):
        line += '_%d,' % j
    line += '_%d,...) _%d' % (i, i)
    print(line)
*/

// Make sure TF_ARG_N() supports at least BOOST_PP_LIMIT_TUPLE arguments.

#define _TF_ARG_ERROR(a, b, c)
#define _TF_ARG_TUPLE_OVERFLOW(a, b, c)

BOOST_PP_IIF(BOOST_PP_EQUAL(1,                                          \
    BOOST_PP_EXPAND(BOOST_PP_CAT(TF_ARG_, _MAX_ARGS) BOOST_PP_LPAREN()  \
    _TF                                                                 \
    BOOST_PP_REPEAT(BOOST_PP_SUB(_MAX_ARGS, 2), _TF_NUM_ARGS_REP, _TF)  \
    BOOST_PP_COMMA() 1 BOOST_PP_RPAREN())),                             \
    BOOST_PP_TUPLE_EAT(1), _TF_ARG_ERROR)(...)

BOOST_PP_IIF(BOOST_PP_GREATER_EQUAL(_MAX_ARGS, BOOST_PP_LIMIT_TUPLE), \
             BOOST_PP_TUPLE_EAT(1), _TF_ARG_TUPLE_OVERFLOW)(...)
 
#endif
コード例 #2
0
// Copyright (c) 2016
// Author: Chrono Law
#include <boost/preprocessor.hpp>

// gcc -std=c++11 -P -E -o a.out functions.cpp;cat a.out;rm a.out

/////////////////

#if __cplusplus < 201103L
    BOOST_PP_ASSERT(0)
#endif

#define x BOOST_PP_MUL(6, 6)

BOOST_PP_ASSERT(BOOST_PP_EQUAL(x, 36))

#undef x

/////////////////

#define helper(z, n, d) BOOST_PP_CAT(d,n)
#define DECL_VARS(n, var) BOOST_PP_ENUM(n, helper, var)

int DECL_VARS(10, x);

#undef helper
#undef DECL_VARS

#define NGX_NULL_HELPER(z, n, d) d
#define NGX_MODULE_NULL(n)      \
    BOOST_PP_ENUM(n, NGX_NULL_HELPER, nullptr)