pputl  0.2.1
pputl Preprocessor Utilities
Modules | Macros
pputl

Modules

 gen
 
 join
 
 tuple
 

Macros

#define PPUTL_ADD(a, b)   PPUTL_DETAIL_ADD_REDUCE(PPUTL_DETAIL_ADD_REDUCER, a, PPUTL_GEN_REPEAT(b, 0))
 
#define PPUTL_CAT(...)   PPUTL_DETAIL_CAT_X(__VA_ARGS__)
 
#define PPUTL_CHOOSE(idx)   PPUTL_CAT(PPUTL_DETAIL_CHOOSE_, idx)
 
#define PPUTL_DEC(n)   PPUTL_CAT(PPUTL_DETAIL_DEC_, n)
 
#define PPUTL_EAT(...)
 
#define PPUTL_EMPTY()
 
#define PPUTL_EQ(a, b)   PPUTL_DETAIL_EQ_X(a, b)
 
#define PPUTL_EXPAND(...)   PPUTL_DETAIL_EXPAND_X(__VA_ARGS__)
 
#define PPUTL_FIRST(...)   PPUTL_DETAIL_FIRST_X(__VA_ARGS__)
 
#define PPUTL_IIF(bit)   PPUTL_CAT(PPUTL_DETAIL_IIF_, bit)
 
#define PPUTL_INC(n)   PPUTL_CAT(PPUTL_DETAIL_INC_, n)
 
#define PPUTL_INCLUDES(n, ...)
 
#define PPUTL_NARGS(...)   PPUTL_DETAIL_NARGS_X(__VA_ARGS__)
 
#define PPUTL_NEQ(a, b)   PPUTL_NOT(PPUTL_EQ(a, b))
 
#define PPUTL_NOT(b)   PPUTL_IIF(b)(0, 1)
 
#define PPUTL_NOTHING
 
#define PPUTL_REDUCE(reducer, initial, ...)
 
#define PPUTL_REST(...)   PPUTL_DETAIL_REST_X(__VA_ARGS__)
 
#define PPUTL_STRINGIZE(...)   PPUTL_DETAIL_STRINGIZE_X(__VA_ARGS__)
 
#define PPUTL_SUM(...)   PPUTL_DETAIL_SUM_REDUCE(PPUTL_DETAIL_SUM_REDUCER, 0, __VA_ARGS__)
 

Detailed Description

Macro Definition Documentation

◆ PPUTL_ADD

#define PPUTL_ADD (   a,
 
)    PPUTL_DETAIL_ADD_REDUCE(PPUTL_DETAIL_ADD_REDUCER, a, PPUTL_GEN_REPEAT(b, 0))

add two numbers together [0, 256)

Parameters
anumber [0, 256)
bnumber [0, 256)
Returns
a + b [0, 256)

◆ PPUTL_CAT

#define PPUTL_CAT (   ...)    PPUTL_DETAIL_CAT_X(__VA_ARGS__)

concatenate [0, 256) args

◆ PPUTL_CHOOSE

#define PPUTL_CHOOSE (   idx)    PPUTL_CAT(PPUTL_DETAIL_CHOOSE_, idx)

expands to arg at index idx [0, 256)

PPUTL_CHOOSE(0)(1, 2, 3) // 1
PPUTL_CHOOSE(1)(1, 2, 3) // 2
PPUTL_CHOOSE(2)(1, 2, 3) // 3
// args are expanded before selection
#define ARGS 1, 2, 3
PPUTL_CHOOSE(0)(ARGS) // 1

◆ PPUTL_DEC

#define PPUTL_DEC (   n)    PPUTL_CAT(PPUTL_DETAIL_DEC_, n)

decrement a number [1, 256)

Parameters
n[1, 256)

◆ PPUTL_EAT

#define PPUTL_EAT (   ...)

eats any arguments; expands to nothing

◆ PPUTL_EMPTY

#define PPUTL_EMPTY ( )

empty macro function for controlled expansion

◆ PPUTL_EQ

#define PPUTL_EQ (   a,
 
)    PPUTL_DETAIL_EQ_X(a, b)

expands to 1 if two numbers a and b [0, 256) are equal, or 0 if not

Parameters
anumber [0, 256)
bnumber [0, 256)

◆ PPUTL_EXPAND

#define PPUTL_EXPAND (   ...)    PPUTL_DETAIL_EXPAND_X(__VA_ARGS__)

Performs a secondary expansion of the provided args

◆ PPUTL_FIRST

#define PPUTL_FIRST (   ...)    PPUTL_DETAIL_FIRST_X(__VA_ARGS__)

return the first passed argument

Parameters
...args
Returns
first arg
#include <pputl/first.h>
PPUTL_FIRST(); // expands to nothing
PPUTL_FIRST(a); // a
PPUTL_FIRST(a, b); // a

◆ PPUTL_IIF

#define PPUTL_IIF (   bit)    PPUTL_CAT(PPUTL_DETAIL_IIF_, bit)

conditionally expands based on a 0 or 1 bit

Parameters
bit0 or 1
Returns
if branch function (t, f) => t|f
// PPUTL_IIF(bit)(t, f)
PPUTL_IIF(1)("t", "f") // "t"
PPUTL_IIF(0)("t", "f") // "f"

◆ PPUTL_INC

#define PPUTL_INC (   n)    PPUTL_CAT(PPUTL_DETAIL_INC_, n)

increment a number [0, 255)

Parameters
n[0, 255)

◆ PPUTL_INCLUDES

#define PPUTL_INCLUDES (   n,
  ... 
)
Value:
1, PPUTL_REDUCE(PPUTL_DETAIL_INCLUDES_REDUCER, (n, 0), __VA_ARGS__))

expands to 1 if numeric args [0, 256) have at least one n value; else 0

Parameters
nnumber to check for
...numeric args; all values and total size ranged [0, 256)

◆ PPUTL_NARGS

#define PPUTL_NARGS (   ...)    PPUTL_DETAIL_NARGS_X(__VA_ARGS__)

Returns the number of args passed [0, 256)

◆ PPUTL_NEQ

#define PPUTL_NEQ (   a,
 
)    PPUTL_NOT(PPUTL_EQ(a, b))

expands to 1 if two numbers a and b [0, 256) are NOT equal, or 0 if not

Parameters
anumber [0, 256)
bnumber [0, 256)

◆ PPUTL_NOT

#define PPUTL_NOT (   b)    PPUTL_IIF(b)(0, 1)

flips the provided bit

Parameters
bbit [0, 1]

◆ PPUTL_NOTHING

#define PPUTL_NOTHING

expands to nothing

◆ PPUTL_REDUCE

#define PPUTL_REDUCE (   reducer,
  initial,
  ... 
)
Value:
PPUTL_DETAIL_REDUCE_CHOOSER(__VA_ARGS__) \
(reducer, initial, \
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, \
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, \
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, \
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, \
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, \
93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, \
109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, \
124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, \
139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, \
154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, \
169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, \
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, \
199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, \
214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, \
229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, \
244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255)__VA_OPT__(, ) \
__VA_ARGS__)

reduces [0, 256) args to one expansion using a reducer macro

warn: REDUCE calls cannot be chained together. Macros utilizing REDUCE cannot be used by other macros using REDUCE. See tools/genReduceMacro to generate this functionality for each use. To create this file: node genReduceMacro PPUTL REDUCE 256 false.

Parameters
reducer- macro function of the form: f(accumulator, current, index) -> accumulator
initial- intial value of the accumulator
...- args to reduce
#include <pputl/add.h>
#include <pputl/reduce.h>
#define SUM_REDUCER(a, v, i) PPUTL_ADD(a, v)
// SUM(): 0; SUM(0): 0; SUM(1): 1; SUM(1, 2, 3): 6
#define SUM(...) PPUTL_REDUCE(SUM_REDUCER, 0, __VA_ARGS__)

◆ PPUTL_REST

#define PPUTL_REST (   ...)    PPUTL_DETAIL_REST_X(__VA_ARGS__)

return all passed arguments except for the first

Parameters
...args
Returns
all args but the first
#include <pputl/rest.h>
PPUTL_REST(); // expands to nothing
PPUTL_REST(a); // expands to nothing
PPUTL_REST(a, b); // b
PPUTL_REST(a, b, c); // b, c

◆ PPUTL_STRINGIZE

#define PPUTL_STRINGIZE (   ...)    PPUTL_DETAIL_STRINGIZE_X(__VA_ARGS__)

stringizes provided args

◆ PPUTL_SUM

#define PPUTL_SUM (   ...)    PPUTL_DETAIL_SUM_REDUCE(PPUTL_DETAIL_SUM_REDUCER, 0, __VA_ARGS__)

sum N numbers [0, 256)

Parameters
anumber [0, 256)
bnumber [0, 256)
Returns
a + b [0, 256)
rest.h
PPUTL_REST - return all passed arguments except for the first
first.h
PPUTL_FIRST - return the first passed argument
add.h
PPUTL_ADD - add two numbers together [0, 256)
reduce.h
PPUTL_REDUCE - reduces [0, 256) args to one expansion using a reducer macro
PPUTL_TUPLE_ELEM
#define PPUTL_TUPLE_ELEM(idx, tup)
Definition: elem.h:41
PPUTL_REST
#define PPUTL_REST(...)
Definition: rest.h:49
PPUTL_REDUCE
#define PPUTL_REDUCE(reducer, initial,...)
Definition: reduce.h:57
PPUTL_FIRST
#define PPUTL_FIRST(...)
Definition: first.h:48
PPUTL_IIF
#define PPUTL_IIF(bit)
Definition: iif.h:47
PPUTL_CHOOSE
#define PPUTL_CHOOSE(idx)
Definition: choose.h:47