GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
Macro Metaprogramming

Preprocessor-based code-generation utilities, tuple helpers, and platform/compiler macros. More...

Macros

#define GMP_EXPAND(...)
 Force the full expansion of macro arguments.
 
#define GMP_IDENTITY(x)
 Identity macro that returns its argument unchanged, forcing expansion.
 
#define GMP_STRINGIFY(x)
 Convert a macro argument to a string literal.
 
#define GMP_CONCAT(lhs, rhs)
 Concatenates two tokens after expanding them.
 
#define GMP_GET_VARARGS(...)
 Get the number of variable arguments.
 
#define GMP_SIZE_OF_VAARGS(...)
 Get the size of variable arguments.
 
#define GMP_IS_EMPTY(...)
 Check if variable arguments are empty.
 
#define GMP_HAS_COMMA(...)
 Check if the variable argument list contains a comma.
 
#define GMP_OPT_COMMA(...)
 Optional comma based on argument emptiness.
 
#define GMP_OVERLOAD_INVOKE(call, ...)
 Call an overloaded macro based on the special version.
 
#define GMP_GET_N(idx, ...)
 Get the N-th parameter from the variable argument list.
 
#define GMP_GET_FIRST_N(n, ...)
 Get the first n arguments from a variadic argument list.
 
#define GMP_REMOVE_PARENS(tup)
 Remove parentheses from a tuple/parameter list.
 
#define GMP_GET_TUPLE(idx, tup)
 Get the nth element from a tuple/parameter list.
 
#define GMP_IS_TUPLE(symbol)
 Tests whether a preprocessor argument is a non-empty tuple.
 
#define GMP_TUPLE_APPEND(tup, x)
 Append an element to the end of a tuple.
 
#define GMP_TUPLE_PREPEND(tup, x)
 Prepend an element to the beginning of a tuple.
 
#define GMP_TUPLE_CONCAT(tup_a, tup_b)
 Concatenate two tuples into a single tuple.
 
#define GMP_TUPLE_SIZE(tup)
 Calculate the number of elements in a tuple.
 
#define GMP_TUPLE_EMPTY(tup)
 Check if a tuple is empty.
 
#define GMP_TUPLE_SKIP(count, tup)
 Skip the first 'count' elements from a tuple and return the remaining elements.
 
#define GMP_TUPLE_TAKE(count, tup)
 Take the first 'count' elements from a tuple.
 
#define GMP_FOR_EACH(call, ...)
 Call a macro for each argument provided.
 
#define GMP_FOR_EACH_INDEPENDENT(call, ...)
 Executes a macro call on each argument independently, supporting nested iteration.
 
#define GMP_WHILE(pred, op, args)
 Repeatedly apply an operation while a predicate remains true.
 
#define GMP_CMP(x, y)
 Compare two numbers by simultaneous decrementing, return final state.
 
#define GMP_INC(value)
 Increment a value by 1.
 
#define GMP_DEC(value)
 Decrement a value by 1.
 
#define GMP_NOT(value)
 Macro to perform logical NOT operation on a value.
 
#define GMP_AND(a, b)
 Macro to perform logical AND operation between two values.
 
#define GMP_OR(a, b)
 Logical OR operation for two boolean values.
 
#define GMP_XOR(a, b)
 Logical XOR (exclusive OR) operation for two boolean values.
 
#define GMP_IMPLIES(p, q)
 Logical implication: p ⇒ q ≡ ¬p ∨ q.
 
#define GMP_BOOL(value)
 Macro to convert a value to a boolean representation.
 
#define GMP_MAX(a, b)
 Returns the maximum of two integer values.
 
#define GMP_MIN(a, b)
 Returns the minimum of two integer values.
 
#define GMP_MINMAX(a, b)
 Returns a tuple containing the minimum and maximum of two values in order.
 
#define GMP_MAXMIN(a, b)
 Returns a tuple containing the maximum and minimum of two values in order.
 
#define GMP_SWAP(a, b)
 Swaps the positions of two values.
 
#define GMP_ADD(a, b)
 Computes the sum of two integer values using iterative addition.
 
#define GMP_SUB(a, b)
 Computes the difference between two integer values (a - b).
 
#define GMP_IF_THEN_ELSE(cond, then_expr, else_expr)
 Conditional selection macro that evaluates to one of two expressions based on a condition.
 
#define GMP_IF(cond, expr)
 Conditional macro expansion based on boolean condition.
 
#define GMP_MAX_INDEX
 Maximum depth allowed for macro nesting.
 
#define GMP_CHECK_INDEX(index)
 Macro to check if an index is within a specified range.
 
#define GMP_CHECK_INDEX_BOOL(index)
 Macro to check if an index is within a specified range.
 
#define GMP_MAKE_INDEX_SEQUENCE(index)
 Generates a comma-separated index sequence up to a given index.
 
#define GMP_EQUAL_INT(i, j)
 Macro to compare two integer values for equality.
 
#define GMP_EQUAL_INT_INDEPENDENT(i, j)
 Compare two integer literal macros without relying on GMP_CMP.
 
#define GMP_LESS_INT(i, j)
 Check if i < j by analyzing comparison result state.
 
#define GMP_LESS_EQUAL_INT(i, j)
 Test if i ≤ j (i is less than or equal to j).
 
#define GMP_GREATER_INT(i, j)
 Check if i > j by analyzing comparison result state.
 
#define GMP_GREATER_EQUAL_INT(i, j)
 Test if i ≥ j (i is greater than or equal to j).
 
#define GMP_SUB_INT(i, j)
 Integer subtraction (i - j)
 
#define GMP_EMPTY(...)
 Macro that expands to nothing.
 
#define GMP_DEFER(id)
 Macro to defer the expansion of another macro.
 
#define GMP_EVAL(...)
 Repeatedly rescan macro output to force deeper recursive expansion.
 
#define GMP_EVAL_1(...)
 
#define GMP_EVAL_2(...)
 
#define GMP_EVAL_3(...)
 
#define GMP_EVAL_4(...)
 
#define GMP_EVAL_5(...)
 
#define GMP_EVAL_6(...)
 
#define GMP_RANGE(begin, end)
 Macro to generate a sequence of numbers from begin to end.
 
#define GMP_REPEAT(call, count, ...)
 Macro to repeat a function call a specified number of times.
 
#define GMP_GENERATE_NAMESPACES_BEGIN(...)
 Generate nested namespaces.
 
#define GMP_GENERATE_NAMESPACES_END(...)
 
#define GMP_CONCATS(x, y, ...)
 Concatenate multiple tokens into a single token.
 
#define GMP_REMOVE_TRAILING_COMMA(...)
 Removes trailing comma from variadic macro arguments.
 
#define GMP_IDENTIFIERS
 Expand to a comma-separated sequence of placeholder identifiers.
 
#define GMP_CPP_STD98
 Numeric __cplusplus value corresponding to C++98.
 
#define GMP_CPP_STD11
 Numeric __cplusplus value corresponding to C++11.
 
#define GMP_CPP_STD14
 Numeric __cplusplus value corresponding to C++14.
 
#define GMP_CPP_STD17
 Numeric __cplusplus value corresponding to C++17.
 
#define GMP_CPP_STD20
 Numeric __cplusplus value corresponding to C++20.
 
#define GMP_CPP_STD23
 Numeric __cplusplus value corresponding to C++23.
 
#define GMP_CPP_STD26
 Numeric __cplusplus value reserved for C++26 support checks.
 
#define GMP_CPP_AT_LEAST(version)
 Check if current C++ standard is greater than or equal to the specified version.
 
#define GMP_CPP_EXACTLY(version)
 Check if current C++ standard is exactly the specified version.
 
#define GMP_CPP_NEWER_THAN(version)
 Check if current C++ standard is newer than the specified version.
 
#define GMP_CPP_OLDER_THAN(version)
 Check if current C++ standard is older than the specified version.
 
#define GMP_INLINE
 Expand to inline when inline variables are supported, otherwise expand to nothing.
 

Platform Detection

Compile-time operating system detection macros.

These macros expose the detected target platform as boolean constants and provide a human-readable platform name.

#define GMP_PLATFORM_WINDOWS
 Evaluate to 1 when compiling for Windows, otherwise 0.
 
#define GMP_PLATFORM_LINUX
 Evaluate to 1 when compiling for Linux, otherwise 0.
 
#define GMP_PLATFORM_MAC
 Evaluate to 1 when compiling for macOS, otherwise 0.
 
#define GMP_PLATFORM_IOS
 Evaluate to 1 when compiling for iOS, otherwise 0.
 
#define GMP_PLATFORM_ANDROID
 Evaluate to 1 when compiling for Android, otherwise 0.
 
#define GMP_PLATFORM_NAME
 Expand to a string literal describing the detected target platform.
 

Compiler Detection

Compile-time compiler detection macros.

These macros identify the active compiler and expose a numeric version and descriptive compiler name.

#define GMP_COMPILER_MSVC
 Evaluate to 1 when compiling with MSVC, otherwise 0.
 
#define GMP_COMPILER_GCC
 Evaluate to 1 when compiling with GCC, otherwise 0.
 
#define GMP_COMPILER_CLANG
 Evaluate to 1 when compiling with Clang, otherwise 0.
 
#define GMP_COMPILER_NAME
 Expand to a string literal describing the detected compiler.
 
#define GMP_COMPILER_VERSION
 Expand to a compiler-specific numeric version value.
 

Build Configuration Detection

Detect whether the current build is a debug or release build.

#define GMP_BUILD_RELEASE
 Evaluate to 1 for release builds, otherwise 0.
 
#define GMP_BUILD_DEBUG
 Evaluate to 1 for debug builds, otherwise 0.
 
#define GMP_BUILD_TYPE
 Expand to a string literal describing the active build configuration.
 

Architecture Detection

Detect the target processor architecture at compile time.

#define GMP_ARCH_X64
 Evaluate to 1 when targeting x64, otherwise 0.
 
#define GMP_ARCH_ARM64
 Evaluate to 1 when targeting ARM64, otherwise 0.
 
#define GMP_ARCH_X86
 Evaluate to 1 when targeting x86, otherwise 0.
 
#define GMP_ARCH_NAME
 Expand to a string literal describing the detected architecture.
 

Preprocessor Capabilities

Describe the supported preprocessor mode and argument limits.

#define GMP_MAX_MACRO_ARGS
 Maximum supported variadic macro arity for the active preprocessor mode.
 
#define GMP_PREPROCESSOR_TYPE
 Expand to a string literal describing the detected preprocessor mode.
 
#define GMP_STANDARD_PREPROCESSOR
 Evaluate to 1 when the compiler provides a standard-conforming preprocessor.
 

Detailed Description

Macro Definition Documentation

◆ GMP_ADD

#define GMP_ADD (   a,
 
)

This macro implements addition by repeatedly incrementing the smaller value while decrementing the larger value.

Parameters
aFirst integer value
bSecond integer value
Returns
The sum of a and b
Note
The implementation ensures that the iteration count equals min(a,b), making it efficient for the typical case where one value is small.
Example
GMP_ADD(2, 3) // expands to 5
GMP_ADD(0, 5) // expands to 5
GMP_ADD(7, 0) // expands to 7
#define GMP_ADD(a, b)
Computes the sum of two integer values using iterative addition.
Definition macro.hpp:3444

Definition at line 3444 of file macro.hpp.

◆ GMP_AND

#define GMP_AND (   a,
 
)

This macro uses overload invocation to perform a logical AND operation. It relies on specific macro definitions for each combination of values.

Parameters
aThe first operand (0 or 1).
bThe second operand (0 or 1).
Returns
1 if both operands are 1, 0 otherwise.

Definition at line 2953 of file macro.hpp.

◆ GMP_ARCH_ARM64

#define GMP_ARCH_ARM64

Definition at line 314 of file platform.hpp.

◆ GMP_ARCH_NAME

#define GMP_ARCH_NAME

Definition at line 316 of file platform.hpp.

◆ GMP_ARCH_X64

#define GMP_ARCH_X64

Definition at line 313 of file platform.hpp.

◆ GMP_ARCH_X86

#define GMP_ARCH_X86

Definition at line 315 of file platform.hpp.

◆ GMP_BOOL

#define GMP_BOOL (   value)

This macro uses overload invocation to convert a value to its boolean representation. It relies on specific macro definitions for each value.

Parameters
valueThe value to convert (0 or non-zero).
Returns
0 if the value is 0, 1 otherwise.

Definition at line 3059 of file macro.hpp.

◆ GMP_BUILD_DEBUG

#define GMP_BUILD_DEBUG

Definition at line 270 of file platform.hpp.

◆ GMP_BUILD_RELEASE

#define GMP_BUILD_RELEASE

Definition at line 271 of file platform.hpp.

◆ GMP_BUILD_TYPE

#define GMP_BUILD_TYPE

Definition at line 272 of file platform.hpp.

◆ GMP_CHECK_INDEX

#define GMP_CHECK_INDEX (   index)

This macro checks if the given index is within a specified range defined by GMP_MAX_INDEX. If the index exceeds GMP_MAX_INDEX, an error is generated; otherwise, it performs no action.

Parameters
indexThe index to check.

Definition at line 3567 of file macro.hpp.

◆ GMP_CHECK_INDEX_BOOL

#define GMP_CHECK_INDEX_BOOL (   index)

This macro checks if the given index is within a specified range defined by GMP_MAX_INDEX. If the index exceeds GMP_MAX_INDEX, an error is generated; otherwise, it performs no action.

Parameters
indexThe index to check.
Returns
1 if the given index is valid, 0 otherwise.

Definition at line 3840 of file macro.hpp.

◆ GMP_CMP

#define GMP_CMP (   x,
 
)

This macro compares two numbers x and y by repeatedly decrementing both values until at least one reaches zero. It returns the final state (x_final, y_final) which indicates the comparison result by their values:

Process examples: GMP_CMP(2, 3) → expands through: (2, 3) → (1, 2) → (0, 1) // returns (0, 1) GMP_CMP(3, 2) → expands through:
(3, 2) → (2, 1) → (1, 0) // returns (1, 0) GMP_CMP(2, 2) → expands through: (2, 2) → (1, 1) → (0, 0) // returns (0, 0)

Result interpretation:

  • (0, 0): x == y (both reached zero simultaneously)
  • (0, y): x < y (x reached zero first, y still positive)
  • (x, 0): x > y (y reached zero first, x still positive)
Parameters
xFirst number to compare (non-negative)
ySecond number to compare (non-negative)
Returns
Final state tuple (x_final, y_final) indicating comparison result

Definition at line 1872 of file macro.hpp.

◆ GMP_COMPILER_CLANG

#define GMP_COMPILER_CLANG

Definition at line 207 of file platform.hpp.

◆ GMP_COMPILER_GCC

#define GMP_COMPILER_GCC

Definition at line 206 of file platform.hpp.

◆ GMP_COMPILER_MSVC

#define GMP_COMPILER_MSVC

Definition at line 205 of file platform.hpp.

◆ GMP_COMPILER_NAME

#define GMP_COMPILER_NAME

Definition at line 208 of file platform.hpp.

◆ GMP_COMPILER_VERSION

#define GMP_COMPILER_VERSION

Definition at line 209 of file platform.hpp.

◆ GMP_CONCAT

#define GMP_CONCAT (   lhs,
  rhs 
)

This macro concatenates two tokens lhs and rhs after expanding them.

Parameters
lhsFirst token.
rhsSecond token.
Returns
The concatenation of the expanded lhs and rhs.
Example
#define FOO 1
#define BAR 2
GMP_CONCAT(FOO, BAR) // Results in 12
#define GMP_CONCAT(lhs, rhs)
Concatenates two tokens after expanding them.
Definition macro.hpp:154

Definition at line 154 of file macro.hpp.

◆ GMP_CONCATS

#define GMP_CONCATS (   x,
  y,
  ... 
)

This macro concatenates all provided tokens into a single token. It accepts two or more arguments and can handle an arbitrary number of tokens (subject to compiler limits).

The macro works by recursively concatenating tokens in pairs:

  1. First concatenate x and y into a single token
  2. Then concatenate that result with the next token
  3. Continue until all tokens are concatenated
Parameters
xFirst token to concatenate
ySecond token to concatenate
...Additional tokens to concatenate (optional)
Returns
A single token formed by concatenating all input tokens
Note
The macro requires at least 2 arguments. For single-token "concatenation", use GMP_IDENTITY or simply pass the token directly.
This macro uses GMP_EVAL to ensure complete expansion of intermediate concatenation results.
Example
#define PREFIX foo
#define SUFFIX bar
// Basic concatenation
GMP_CONCATS(a, b, c) // expands to abc
GMP_CONCATS(1, 2, 3, 4) // expands to 1234
// With macro expansion
GMP_CONCATS(PREFIX, _, SUFFIX) // expands to foo_bar
// Creating identifiers
GMP_CONCATS(func_, 1) // expands to func_1
GMP_CONCATS(TYPE, _ptr) // expands to TYPE_ptr
// Multiple concatenations
GMP_CONCATS(a, b, c, d, e) // expands to abcde
#define GMP_CONCATS(x, y,...)
Concatenate multiple tokens into a single token.
Definition macro.hpp:4954
Comparison with GMP_CONCAT
Warning
Avoid excessive recursion depth. While the macro can handle many tokens, very long argument lists may hit compiler limits.
See also
GMP_CONCAT for concatenating exactly two tokens
GMP_STRINGIFY for converting tokens to string literals
GMP_EXPAND for ensuring macro expansion

Definition at line 4954 of file macro.hpp.

◆ GMP_CPP_AT_LEAST

#define GMP_CPP_AT_LEAST (   version)

This macro checks if the current C++ standard meets or exceeds the given version.

Example: GMP_CPP_AT_LEAST(17) // true if C++17 or newer GMP_CPP_AT_LEAST(20) // true if C++20 or newer

Parameters
versionThe C++ standard version year (98, 11, 14, 17, 20, 23, 26)

Definition at line 5046 of file macro.hpp.

◆ GMP_CPP_EXACTLY

#define GMP_CPP_EXACTLY (   version)

This macro checks if the current C++ standard exactly matches the given version.

Example: GMP_CPP_EXACTLY(17) // true only for C++17

Parameters
versionThe C++ standard version year

Definition at line 5059 of file macro.hpp.

◆ GMP_CPP_NEWER_THAN

#define GMP_CPP_NEWER_THAN (   version)

This macro checks if the current C++ standard is strictly newer than the given version.

Example: GMP_CPP_NEWER_THAN(17) // true for C++20, C++23, etc.

Parameters
versionThe C++ standard version year

Definition at line 5072 of file macro.hpp.

◆ GMP_CPP_OLDER_THAN

#define GMP_CPP_OLDER_THAN (   version)

This macro checks if the current C++ standard is strictly older than the given version.

Example: GMP_CPP_OLDER_THAN(17) // true for C++14, C++11, etc.

Parameters
versionThe C++ standard version year

Definition at line 5085 of file macro.hpp.

◆ GMP_CPP_STD11

#define GMP_CPP_STD11

Definition at line 5027 of file macro.hpp.

◆ GMP_CPP_STD14

#define GMP_CPP_STD14

Definition at line 5028 of file macro.hpp.

◆ GMP_CPP_STD17

#define GMP_CPP_STD17

Definition at line 5029 of file macro.hpp.

◆ GMP_CPP_STD20

#define GMP_CPP_STD20

Definition at line 5030 of file macro.hpp.

◆ GMP_CPP_STD23

#define GMP_CPP_STD23

Definition at line 5031 of file macro.hpp.

◆ GMP_CPP_STD26

#define GMP_CPP_STD26

Definition at line 5032 of file macro.hpp.

◆ GMP_CPP_STD98

#define GMP_CPP_STD98

Definition at line 5026 of file macro.hpp.

◆ GMP_DEC

#define GMP_DEC (   value)

This macro uses overload invocation to decrement a value by 1. It relies on specific macro definitions for each value.

Parameters
valueThe value to decrement.
Returns
The decremented value.

Definition at line 2412 of file macro.hpp.

◆ GMP_DEFER

#define GMP_DEFER (   id)

This macro is used to defer the expansion of the given macro id by inserting an additional layer of indirection. This can be useful in certain macro programming scenarios where immediate expansion of a macro needs to be prevented.

Parameters
idThe macro to be deferred.
Returns
This macro does not return any value. It simply defers the expansion of id.
Example
#define Bar() 1
Bar() // Expands to: 1
GMP_DEFER(Bar)() // Expands to: Bar()
#define GMP_DEFER(id)
Macro to defer the expansion of another macro.
Definition macro.hpp:4796

Definition at line 4796 of file macro.hpp.

◆ GMP_EMPTY

#define GMP_EMPTY (   ...)

This macro expands to nothing and is used to assist other macros in achieving specific functionalities, such as delayed expansion or conditional compilation.

Returns
This macro does not return any value or generate any output.

Definition at line 4776 of file macro.hpp.

◆ GMP_EQUAL_INT

#define GMP_EQUAL_INT (   i,
 
)

This macro compares two integer values, i and j, and returns 1 if they are equal, and 0 if they are not. The maximum values for i and j should not exceed GMP_MAX_INDEX.

Parameters
iThe first integer value to compare.
jThe second integer value to compare.
Returns
1 if i and j are equal, 0 otherwise.

Definition at line 4128 of file macro.hpp.

◆ GMP_EQUAL_INT_INDEPENDENT

#define GMP_EQUAL_INT_INDEPENDENT (   i,
 
)
Parameters
iThe first integer value to compare.
jThe second integer value to compare.
Returns
1 when i and j are equal, otherwise 0.

Definition at line 4140 of file macro.hpp.

◆ GMP_EVAL

#define GMP_EVAL (   ...)
Parameters
...The macro expression to rescan.
Returns
The fully rescanned macro expansion result.

Definition at line 4806 of file macro.hpp.

◆ GMP_EVAL_1

#define GMP_EVAL_1 (   ...)

Definition at line 4807 of file macro.hpp.

◆ GMP_EVAL_2

#define GMP_EVAL_2 (   ...)

Definition at line 4808 of file macro.hpp.

◆ GMP_EVAL_3

#define GMP_EVAL_3 (   ...)

Definition at line 4809 of file macro.hpp.

◆ GMP_EVAL_4

#define GMP_EVAL_4 (   ...)

Definition at line 4810 of file macro.hpp.

◆ GMP_EVAL_5

#define GMP_EVAL_5 (   ...)

Definition at line 4811 of file macro.hpp.

◆ GMP_EVAL_6

#define GMP_EVAL_6 (   ...)

Definition at line 4812 of file macro.hpp.

◆ GMP_EXPAND

#define GMP_EXPAND (   ...)

This macro forces the complete expansion of its arguments. It is commonly used as an intermediate step to ensure that macro arguments are fully evaluated before being passed to other macros. Unlike simple argument substitution, this macro guarantees that nested macros are expanded to their final form.

Parameters
...The macro argument(s) to be expanded.
Returns
The fully expanded result of the argument(s).
Example
#define FOO 42
#define BAR FOO
#define BAZ(x) GMP_EXPAND(x)
int value = BAZ(BAR); // value will be 42
See also
GMP_IDENTITY for a simpler single-argument version

Definition at line 46 of file macro.hpp.

◆ GMP_FOR_EACH

#define GMP_FOR_EACH (   call,
  ... 
)

This macro allows for the invocation of a given macro on each argument in a list of arguments. It expands to a series of calls to the provided macro, one for each argument.

Example usage:

#define DECLARE_VARIABLES(num) int variable_ ## num;
GMP_FOR_EACH(DECLARE_VARIABLES, 1, 2) // Expands to: int variable_1; int variable_2;
#define GMP_FOR_EACH(call,...)
Call a macro for each argument provided.
Definition macro.hpp:1290
Parameters
callThe macro to be called for each argument.
...The list of arguments to be passed to the macro.

Definition at line 1290 of file macro.hpp.

◆ GMP_FOR_EACH_INDEPENDENT

#define GMP_FOR_EACH_INDEPENDENT (   call,
  ... 
)

This macro applies a given macro to each argument in the variadic list, similar to GMP_FOR_EACH but designed specifically to support nested macro iteration scenarios.

Unlike GMP_FOR_EACH, this macro can be nested with GMP_FOR_EACH to enable multi-level iteration, as regular GMP_FOR_EACH cannot be recursively called due to macro expansion limitations.

Parameters
callThe macro to apply to each element (must be a macro that takes one argument)
...Variable number of arguments to process
Note
The primary purpose of this macro is to work alongside GMP_FOR_EACH for nested iterations. Using GMP_FOR_EACH alone for nested scenarios is not possible due to macro recursion restrictions.
See also
GMP_FOR_EACH for the standard non-nestable version

Definition at line 1569 of file macro.hpp.

◆ GMP_GENERATE_NAMESPACES_BEGIN

#define GMP_GENERATE_NAMESPACES_BEGIN (   ...)

These macros create a series of nested namespaces from a list of namespace names.

Example: GMP_GENERATE_NAMESPACES_BEGIN(outer, inner, detail) GMP_GENERATE_NAMESPACES_END(outer, inner, detail)

Expands to: namespace outer { namespace inner { namespace detail { } } }

Parameters
...Variable list of namespace names to create nested hierarchy

Definition at line 4895 of file macro.hpp.

◆ GMP_GENERATE_NAMESPACES_END

#define GMP_GENERATE_NAMESPACES_END (   ...)

Definition at line 4896 of file macro.hpp.

◆ GMP_GET_FIRST_N

#define GMP_GET_FIRST_N (   n,
  ... 
)
Parameters
nThe number of leading arguments to keep.
...The source variadic argument list.
Returns
The first n arguments from __VA_ARGS__.

Definition at line 684 of file macro.hpp.

◆ GMP_GET_N

#define GMP_GET_N (   idx,
  ... 
)
Parameters
idxZero-based index of the parameter to retrieve
...Variable argument list
Returns
The parameter at the specified index, or empty if index out of bounds
Example
GMP_GET_N(0, a, b, c) // expands to: a
GMP_GET_N(1, a, b, c) // expands to: b
GMP_GET_N(2, a, b, c) // expands to: c
#define GMP_GET_N(idx,...)
Get the N-th parameter from the variable argument list.
Definition macro.hpp:414

Definition at line 414 of file macro.hpp.

◆ GMP_GET_TUPLE

#define GMP_GET_TUPLE (   idx,
  tup 
)

This macro extracts the element at the specified index from a parenthesized tuple or parameter list. The tuple is first converted to a parameter sequence by removing parentheses, then the nth element is selected.

Example: GMP_GET_TUPLE(0, (int, float, char)) // Expands to: int GMP_GET_TUPLE(1, (42, "hello", 3.14)) // Expands to: "hello"

Parameters
idxZero-based index of the element to retrieve
tupParenthesized tuple containing the elements
Note
The tuple must contain at least (idx + 1) elements. If idx is out of bounds, the behavior is undefined.

Definition at line 978 of file macro.hpp.

◆ GMP_GET_VARARGS

#define GMP_GET_VARARGS (   ...)

This macro calculates the number of variable arguments passed to it by expanding all arguments recursively until the last one is found, determining the count of arguments.

Parameters
...Variable argument list
Returns
Number of arguments

Definition at line 167 of file macro.hpp.

◆ GMP_GREATER_EQUAL_INT

#define GMP_GREATER_EQUAL_INT (   i,
 
)

Returns 1 if i is greater than or equal to j, 0 otherwise. Implements: i ≥ j ≡ (i > j) ∨ (i == j)

Parameters
iFirst integer
jSecond integer
Returns
1 if i ≥ j, 0 otherwise
Note
This is logically equivalent to NOT(i < j)
Example
GMP_GREATER_EQUAL_INT(5, 3) // expands to 1 (true)
GMP_GREATER_EQUAL_INT(3, 5) // expands to 0 (false)
GMP_GREATER_EQUAL_INT(4, 4) // expands to 1 (true)
GMP_GREATER_EQUAL_INT(0, 0) // expands to 1 (true)
#define GMP_GREATER_EQUAL_INT(i, j)
Test if i ≥ j (i is greater than or equal to j).
Definition macro.hpp:4746
See also
GMP_GREATER_INT for strict greater than (>)
GMP_EQUAL_INT for equality (==)
GMP_LESS_EQUAL_INT for less than or equal (≤)

Definition at line 4746 of file macro.hpp.

◆ GMP_GREATER_INT

#define GMP_GREATER_INT (   i,
 
)

This macro checks if the first number is greater than the second by analyzing the final state (i_final, j_final) from the comparison process.

Mathematical logic: i > j ⇔ (i_final > 0) && (j_final == 0)

Parameters
iFirst number to compare
jSecond number to compare
Returns
1 if i > j, 0 otherwise

Definition at line 4717 of file macro.hpp.

◆ GMP_HAS_COMMA

#define GMP_HAS_COMMA (   ...)

This macro checks if the variable argument list contains a comma. It expands the arguments and uses the _GMP_COMMA_CHECK macro to perform the actual check.

Parameters
...Variable argument list.
Returns
1 if a comma is found, otherwise 0.

Definition at line 283 of file macro.hpp.

◆ GMP_IDENTIFIERS

#define GMP_IDENTIFIERS

This macro is primarily used to build large preprocessor parameter lists.

Definition at line 4993 of file macro.hpp.

◆ GMP_IDENTITY

#define GMP_IDENTITY (   x)

This macro serves as the identity function for macros - it returns its argument exactly as provided. It forces the full expansion of its argument, similar to GMP_EXPAND, but with a different name that can help avoid macro recursion issues in certain contexts.

Parameters
xThe value to return unchanged.
Returns
The fully expanded argument x.
Note
In terms of functionality, GMP_IDENTITY and GMP_EXPAND are identical - both force the expansion of their arguments. However, they exist as separate macros for the following reasons:
  1. Macro Recursion Avoidance: When GMP_EXPAND is heavily used throughout a macro library, there may be edge cases where recursive macro expansion causes issues. Having GMP_IDENTITY as an alternative allows breaking potential recursion cycles.
  2. Code Readability: GMP_IDENTITY clearly communicates the intent of passing an argument through unchanged, while GMP_EXPAND emphasizes the expansion aspect.
  3. Implementation Flexibility: Some macro patterns may work better with one name versus the other due to how the preprocessor resolves macro names.
Practical Usage
In most cases, GMP_EXPAND and GMP_IDENTITY can be used interchangeably. Choose GMP_IDENTITY when:
  • You encounter macro recursion issues with GMP_EXPAND
  • You want to emphasize the identity function aspect
  • Following existing patterns in your codebase
Example
#define FOO BAR
#define BAR 42
// Both produce the same result
int a = GMP_EXPAND(FOO); // expands to 42
int b = GMP_IDENTITY(FOO); // also expands to 42
// Usage in macro definitions
#define ADD(x, y) GMP_IDENTITY(x + y)
int sum = ADD(10, 20); // expands to 10 + 20
#define GMP_IDENTITY(x)
Identity macro that returns its argument unchanged, forcing expansion.
Definition macro.hpp:101
#define GMP_EXPAND(...)
Force the full expansion of macro arguments.
Definition macro.hpp:46
See also
GMP_EXPAND for the variadic version that can handle multiple arguments

Definition at line 101 of file macro.hpp.

◆ GMP_IF

#define GMP_IF (   cond,
  expr 
)

This macro expands to expr if cond evaluates to true (non-zero), otherwise expands to nothing (empty expansion).

Parameters
condBoolean condition (0 = false, non-zero = true)
exprExpression to expand if condition is true
Returns
expr if cond is true, otherwise nothing
Note
Unlike GMP_IF_THEN_ELSE, this macro only has a "then" branch.
The condition is evaluated as boolean (0 = false, other = true).
Example
// Expand based on condition
#define DEBUG_MODE 1
GMP_IF(DEBUG_MODE, std::cout << "Debug message\n";)
// Expands to: std::cout << "Debug message\n";
#define RELEASE_MODE 0
GMP_IF(RELEASE_MODE, std::cout << "Release message\n";)
// Expands to: (nothing)
// Use with other macros
#define LOG_IF(cond, msg) GMP_IF(cond, LOG(msg))
LOG_IF(1, "This will be logged")
LOG_IF(0, "This will not be logged")
#define GMP_IF(cond, expr)
Conditional macro expansion based on boolean condition.
Definition macro.hpp:3544
See also
GMP_IF_THEN_ELSE for if-then-else with both branches
GMP_BOOL for explicit boolean conversion

Definition at line 3544 of file macro.hpp.

◆ GMP_IF_THEN_ELSE

#define GMP_IF_THEN_ELSE (   cond,
  then_expr,
  else_expr 
)

This macro provides a functional-style if-then-else construct that can be used in preprocessor contexts. It selects between then_expr and else_expr based on the boolean value of cond.

Parameters
condCondition value (0 for false, any other value for true)
then_exprExpression to evaluate if cond is true (non-zero)
else_exprExpression to evaluate if cond is false (zero)
Returns
then_expr if cond is true, else_expr if cond is false
Note
The condition cond should be a simple value (0 or 1) for reliable behavior
Both then_expr and else_expr are fully evaluated by the preprocessor
Example
#define DEBUG_LEVEL 1
GMP_IF_THEN_ELSE(DEBUG_LEVEL, "Debug mode", "Release mode")
// Expands to: "Debug mode"
GMP_IF_THEN_ELSE(0, "This won't appear", "This will appear")
// Expands to: "This will appear"
#define GMP_IF_THEN_ELSE(cond, then_expr, else_expr)
Conditional selection macro that evaluates to one of two expressions based on a condition.
Definition macro.hpp:3505

Definition at line 3505 of file macro.hpp.

◆ GMP_IMPLIES

#define GMP_IMPLIES (   p,
 
)

Definition at line 3047 of file macro.hpp.

◆ GMP_INC

#define GMP_INC (   value)

This macro uses overload invocation to increment a value by 1. It relies on specific macro definitions for each value.

Parameters
valueThe value to increment.
Returns
The incremented value.

Definition at line 1887 of file macro.hpp.

◆ GMP_INLINE

#define GMP_INLINE

Definition at line 5095 of file macro.hpp.

◆ GMP_IS_EMPTY

#define GMP_IS_EMPTY (   ...)

This macro checks if the variable arguments are empty by expanding and evaluating the arguments in various forms. It uses helper macros to perform the actual checks.

Parameters
...Variable argument list
Returns
1 if variable arguments are empty, otherwise 0.
Example
GMP_IS_EMPTY(1) // 0
GMP_IS_EMPTY(1, 2) // 0
#define GMP_IS_EMPTY(...)
Check if variable arguments are empty.
Definition macro.hpp:259

Definition at line 259 of file macro.hpp.

◆ GMP_IS_TUPLE

#define GMP_IS_TUPLE (   symbol)

Evaluates to 1 if symbol is a non-empty parenthesized list (e.g., (a, b, c)), and 0 if it is empty or not a tuple.

Definition at line 987 of file macro.hpp.

◆ GMP_LESS_EQUAL_INT

#define GMP_LESS_EQUAL_INT (   i,
 
)

Returns 1 if i is less than or equal to j, 0 otherwise. Implements: i ≤ j ≡ (i < j) ∨ (i == j)

Parameters
iFirst integer
jSecond integer
Returns
1 if i ≤ j, 0 otherwise
Note
This is logically equivalent to NOT(i > j)
Example
GMP_LESS_EQUAL_INT(3, 5) // expands to 1 (true)
GMP_LESS_EQUAL_INT(5, 3) // expands to 0 (false)
GMP_LESS_EQUAL_INT(4, 4) // expands to 1 (true)
GMP_LESS_EQUAL_INT(0, 0) // expands to 1 (true)
#define GMP_LESS_EQUAL_INT(i, j)
Test if i ≤ j (i is less than or equal to j).
Definition macro.hpp:4701
See also
GMP_LESS_INT for strict less than (<)
GMP_EQUAL_INT for equality (==)
GMP_GREATER_EQUAL_INT for greater than or equal (≥)

Definition at line 4701 of file macro.hpp.

◆ GMP_LESS_INT

#define GMP_LESS_INT (   i,
 
)

This macro checks if the first number is less than the second by analyzing the final state (i_final, j_final) from the comparison process.

Mathematical logic: i < j ⇔ (i_final == 0) && (j_final > 0)

Parameters
iFirst number to compare
jSecond number to compare
Returns
True if i < j, false otherwise

Definition at line 4672 of file macro.hpp.

◆ GMP_MAKE_INDEX_SEQUENCE

#define GMP_MAKE_INDEX_SEQUENCE (   index)

This macro uses overload invocation and recursive macro expansion to generate a comma-separated sequence of indices from 0 up to the specified index.

Parameters
indexThe maximum index value to include in the sequence.
Returns
A comma-separated sequence of indices.

Definition at line 3855 of file macro.hpp.

◆ GMP_MAX

#define GMP_MAX (   a,
 
)

This macro compares two integers a and b and returns the larger value.

Parameters
aFirst integer value
bSecond integer value
Returns
The maximum of a and b
Note
Both values should be within the valid range of GMP integer operations.
Example
GMP_MAX(3, 7) // expands to 7
GMP_MAX(10, 2) // expands to 10
GMP_MAX(5, 5) // expands to 5
#define GMP_MAX(a, b)
Returns the maximum of two integer values.
Definition macro.hpp:3338

Definition at line 3338 of file macro.hpp.

◆ GMP_MAX_INDEX

#define GMP_MAX_INDEX

This macro defines the maximum depth allowed for macro nesting. Exceeding this depth may lead to compiler errors or warnings related to macro recursion depth.

Definition at line 3556 of file macro.hpp.

◆ GMP_MAX_MACRO_ARGS

#define GMP_MAX_MACRO_ARGS

Definition at line 342 of file platform.hpp.

◆ GMP_MAXMIN

#define GMP_MAXMIN (   a,
 
)

This macro returns a tuple (max, min) where the first element is the larger value and the second element is the smaller value.

Parameters
aFirst integer value
bSecond integer value
Returns
Tuple (max, min) in descending order
Example
GMP_MAXMIN(7, 3) // expands to (7, 3)
GMP_MAXMIN(2, 10) // expands to (10, 2)
GMP_MAXMIN(5, 5) // expands to (5, 5)
#define GMP_MAXMIN(a, b)
Returns a tuple containing the maximum and minimum of two values in order.
Definition macro.hpp:3401

Definition at line 3401 of file macro.hpp.

◆ GMP_MIN

#define GMP_MIN (   a,
 
)

This macro compares two integers a and b and returns the smaller value.

Parameters
aFirst integer value
bSecond integer value
Returns
The minimum of a and b
Example
GMP_MIN(3, 7) // expands to 3
GMP_MIN(10, 2) // expands to 2
GMP_MIN(5, 5) // expands to 5
#define GMP_MIN(a, b)
Returns the minimum of two integer values.
Definition macro.hpp:3359

Definition at line 3359 of file macro.hpp.

◆ GMP_MINMAX

#define GMP_MINMAX (   a,
 
)

This macro returns a tuple (min, max) where the first element is the smaller value and the second element is the larger value.

Parameters
aFirst integer value
bSecond integer value
Returns
Tuple (min, max) in ascending order
Example
GMP_MINMAX(7, 3) // expands to (3, 7)
GMP_MINMAX(2, 10) // expands to (2, 10)
GMP_MINMAX(5, 5) // expands to (5, 5)
#define GMP_MINMAX(a, b)
Returns a tuple containing the minimum and maximum of two values in order.
Definition macro.hpp:3380

Definition at line 3380 of file macro.hpp.

◆ GMP_NOT

#define GMP_NOT (   value)

This macro uses overload invocation to perform a logical NOT operation. It relies on specific macro definitions for each value.

Parameters
valueThe value to perform logical NOT on.
Returns
1 if the value is 0, 0 otherwise.

Definition at line 2938 of file macro.hpp.

◆ GMP_OPT_COMMA

#define GMP_OPT_COMMA (   ...)

This macro adds a comma if the arguments are empty, otherwise it does not add a comma.

Parameters
...Variable argument list.
Returns
Comma if arguments are empty, otherwise nothing.

Definition at line 364 of file macro.hpp.

◆ GMP_OR

#define GMP_OR (   a,
 
)

This macro computes the logical OR of two boolean values a and b. Both arguments are treated as boolean values (0 = false, non-zero = true).

Truth table:

Parameters
aFirst boolean value (0 or non-zero)
bSecond boolean value (0 or non-zero)
Returns
1 if either a or b is non-zero, 0 otherwise
Note
Non-zero values are treated as true (1).
Example
GMP_OR(0, 0) // expands to 0
GMP_OR(0, 1) // expands to 1
GMP_OR(GMP_BOOL(5), 0) // expands to 1 (5 is non-zero, treated as true)
GMP_OR(GMP_BOOL(3), GMP_BOOL(7)) // expands to 1 (both non-zero)
#define GMP_BOOL(value)
Macro to convert a value to a boolean representation.
Definition macro.hpp:3059
#define GMP_OR(a, b)
Logical OR operation for two boolean values.
Definition macro.hpp:2990
See also
GMP_AND for logical AND operation
GMP_NOT for logical NOT operation

Definition at line 2990 of file macro.hpp.

◆ GMP_OVERLOAD_INVOKE

#define GMP_OVERLOAD_INVOKE (   call,
  ... 
)

This macro allows for the invocation of different versions of a macro depending on the version provided. It works by concatenating the base call name with the version argument, and then invoking the appropriate overloaded macro.

Example usage:

#define TEST_1(x) printf("One argument: %c\n", (x))
#define TEST_1_1(x, y) printf("Two arguments: %c, %c\n", (x), (y))
GMP_OVERLOAD_INVOKE(TEST, 1)('a'); // Expands to: TEST_1('a')
GMP_OVERLOAD_INVOKE(TEST, 1, 1)('a', 'b'); // Expands to: TEST_1_1('a', 'b')
#define GMP_OVERLOAD_INVOKE(call,...)
Call an overloaded macro based on the special version.
Definition macro.hpp:392
Parameters
callThe base macro to be called.
...The arguments to be passed to the macro. The arguments determine which overloaded version of the macro is invoked.

Definition at line 392 of file macro.hpp.

◆ GMP_PLATFORM_ANDROID

#define GMP_PLATFORM_ANDROID

Definition at line 89 of file platform.hpp.

◆ GMP_PLATFORM_IOS

#define GMP_PLATFORM_IOS

Definition at line 88 of file platform.hpp.

◆ GMP_PLATFORM_LINUX

#define GMP_PLATFORM_LINUX

Definition at line 86 of file platform.hpp.

◆ GMP_PLATFORM_MAC

#define GMP_PLATFORM_MAC

Definition at line 87 of file platform.hpp.

◆ GMP_PLATFORM_NAME

#define GMP_PLATFORM_NAME

Definition at line 90 of file platform.hpp.

◆ GMP_PLATFORM_WINDOWS

#define GMP_PLATFORM_WINDOWS

Definition at line 85 of file platform.hpp.

◆ GMP_PREPROCESSOR_TYPE

#define GMP_PREPROCESSOR_TYPE

Definition at line 343 of file platform.hpp.

◆ GMP_RANGE

#define GMP_RANGE (   begin,
  end 
)

This macro generates a sequence of numbers starting from begin and ending at end. The value of end should not exceed GMP_MAX_INT.

Parameters
beginThe starting number of the sequence.
endThe ending number of the sequence. Must be less than or equal to GMP_MAX_INT.
Returns
A sequence of numbers from begin to end.
Note
The end value should not be greater than GMP_MAX_INT.

Definition at line 4827 of file macro.hpp.

◆ GMP_REMOVE_PARENS

#define GMP_REMOVE_PARENS (   tup)

This macro is used to remove the parentheses surrounding a tuple or parameter list, converting it into a comma-separated sequence of arguments. Primarily used in variadic macros to process parenthesized argument groups.

Example: GMP_REMOVE_PARENS((int, float, char)) // Expands to: int, float, char GMP_REMOVE_PARENS((42, "hello", 3.14)) // Expands to: 42, "hello", 3.14

Definition at line 957 of file macro.hpp.

◆ GMP_REMOVE_TRAILING_COMMA

#define GMP_REMOVE_TRAILING_COMMA (   ...)

This macro eliminates the trailing comma that may appear in variadic arguments, particularly useful when dealing with empty argument lists or conditional macro expansions.

Note
This is a helper macro that works in conjunction with other GMP tuple utilities.

Example usage:

GMP_REMOVE_TRAILING_COMMA(a, b, c,) // Expands to: a, b, c
GMP_REMOVE_TRAILING_COMMA() // Expands to:
GMP_REMOVE_TRAILING_COMMA(,) // Expands to:
GMP_REMOVE_TRAILING_COMMA(_0,) // Expands to: _0
#define GMP_REMOVE_TRAILING_COMMA(...)
Removes trailing comma from variadic macro arguments.
Definition macro.hpp:4980
Parameters
...Variadic arguments (may include a trailing comma)
Returns
Arguments without trailing comma, wrapped in parentheses

Definition at line 4980 of file macro.hpp.

◆ GMP_REPEAT

#define GMP_REPEAT (   call,
  count,
  ... 
)

This macro executes the function call call repeatedly for count iterations. The arguments for the function call are provided by VA_ARGS.

Parameters
callThe function or macro to be called in each iteration.
countThe number of times the function call should be executed.
...Additional arguments passed to each invocation of call.
Note
The count value should not be greater than GMP_MAX_INT.
Example
void bar(int arg1, const char* arg2) {
printf("bar %d, %s\n", arg1, arg2);
}
#define Bar(arg1, arg2) bar(arg1, arg2);
GMP_REPEAT(Bar, 3, 1, "arg2") // Execute bar function 3 times
// Expands to: bar(1, "arg2"); bar(1, "arg2"); bar(1, "arg2");
#define GMP_REPEAT(call, count,...)
Macro to repeat a function call a specified number of times.
Definition macro.hpp:4868
Error Handling
If count exceeds GMP_MAX_INT, a compile-time error is triggered via GMP_CHECK_INDEX. For valid counts, the macro executes safely.
See also
GMP_CHECK_INDEX for index validation
GMP_EVAL for expression evaluation

Definition at line 4868 of file macro.hpp.

◆ GMP_SIZE_OF_VAARGS

#define GMP_SIZE_OF_VAARGS (   ...)
Parameters
...Variable argument list
Returns
Size of arguments
Example
GMP_SIZE_OF_VAARGS('a', 'b') // 2
GMP_SIZE_OF_VAARGS('a', 'b', 'c') // 3
GMP_SIZE_OF_VAARGS('a', 'b', 1, 2) // 4
GMP_SIZE_OF_VAARGS('a', 'b', 1, 2, 3, 4) // 6
#define GMP_SIZE_OF_VAARGS(...)
Get the size of variable arguments.
Definition macro.hpp:217

Definition at line 217 of file macro.hpp.

◆ GMP_STANDARD_PREPROCESSOR

#define GMP_STANDARD_PREPROCESSOR

Definition at line 344 of file platform.hpp.

◆ GMP_STRINGIFY

#define GMP_STRINGIFY (   x)

This macro converts its argument x into a string literal. Unlike directly using the # operator, this macro ensures that x is fully expanded before being stringified. This is important when x is itself a macro that needs to be expanded.

Parameters
xThe value to convert to a string.
Returns
A string literal containing the expanded value of x.
Example
#define VERSION_MAJOR 2
#define VERSION_MINOR 15
#define VERSION VERSION_MAJOR ## . ## VERSION_MINOR
// Without GMP_STRINGIFY:
const char* str1 = #VERSION; // "VERSION"
// With GMP_STRINGIFY:
const char* str2 = GMP_STRINGIFY(VERSION); // "2.15"
#define GMP_STRINGIFY(x)
Convert a macro argument to a string literal.
Definition macro.hpp:132
Note
This macro works by first passing x through GMP_EXPAND to ensure full expansion, then using the stringify operator #.

Definition at line 132 of file macro.hpp.

◆ GMP_SUB

#define GMP_SUB (   a,
 
)

This macro implements subtraction with support for negative results. If a >= b, returns a - b. If a < b, returns -(b - a).

Parameters
aFirst integer value (minuend)
bSecond integer value (subtrahend)
Returns
The difference a - b (may be negative)
Example
GMP_SUB(5, 3) // expands to 2
GMP_SUB(3, 5) // expands to -2
GMP_SUB(7, 7) // expands to 0
GMP_SUB(0, 0) // expands to 0
#define GMP_SUB(a, b)
Computes the difference between two integer values (a - b).
Definition macro.hpp:3471
Note
The negative result is represented with a minus sign prefix.

Definition at line 3471 of file macro.hpp.

◆ GMP_SUB_INT

#define GMP_SUB_INT (   i,
 
)

Returns the result of subtracting j from i. Result can be negative, but input parameters must be non-negative.

Example: GMP_SUB_INT(9, 14) → -5 GMP_SUB_INT(23, 14) → 9 GMP_SUB_INT(8, 8) → 0

Parameters
iMinuend (non-negative integer)
jSubtrahend (non-negative integer)
Returns
i - j (can be negative)

Definition at line 4764 of file macro.hpp.

◆ GMP_SWAP

#define GMP_SWAP (   a,
 
)

This macro simply returns its arguments in reversed order. It can be used as a building block for more complex operations.

Parameters
aFirst value
bSecond value
Returns
Tuple (b, a) with arguments swapped
Example
GMP_SWAP(x, y) // expands to y, x
#define GMP_SWAP(a, b)
Swaps the positions of two values.
Definition macro.hpp:3420

Definition at line 3420 of file macro.hpp.

◆ GMP_TUPLE_APPEND

#define GMP_TUPLE_APPEND (   tup,
 
)

This macro creates a new tuple by adding the element x to the end of the input tuple tup. It handles both empty and non-empty tuples correctly.

Parameters
tupThe input tuple (may be empty)
xThe element to append to the tuple
Returns
A new tuple with x added at the end
Note
If tup is empty, the result is a single-element tuple containing x.
This macro ensures proper parentheses handling for empty tuples.
Example
// Append to non-empty tuple
GMP_TUPLE_APPEND((a, b, c), d) // expands to (a, b, c, d)
// Append to empty tuple
GMP_TUPLE_APPEND((), x) // expands to (x)
// Chaining append operations
GMP_TUPLE_APPEND(GMP_TUPLE_APPEND((a, b), c), d) // expands to (a, b, c, d)
#define GMP_TUPLE_APPEND(tup, x)
Append an element to the end of a tuple.
Definition macro.hpp:1020
See also
GMP_TUPLE_PREPEND for adding elements to the beginning
GMP_TUPLE_CONCAT for concatenating two tuples

Definition at line 1020 of file macro.hpp.

◆ GMP_TUPLE_CONCAT

#define GMP_TUPLE_CONCAT (   tup_a,
  tup_b 
)

This macro combines two tuples tup_a and tup_b into a new tuple that contains all elements from tup_a followed by all elements from tup_b. The macro efficiently handles edge cases where one or both tuples are empty.

Parameters
tup_aThe first tuple (elements will appear first in the result)
tup_bThe second tuple (elements will appear after tup_a's elements)
Returns
A new tuple containing all elements from both input tuples in order
Note
If both tuples are empty, the result is an empty tuple.
If one tuple is empty, the result is simply the other tuple.
The macro ensures proper parentheses handling and avoids unnecessary commas.
Example
// Concatenate two non-empty tuples
GMP_TUPLE_CONCAT((a, b), (c, d)) // expands to (a, b, c, d)
// First tuple empty
GMP_TUPLE_CONCAT((), (x, y, z)) // expands to (x, y, z)
// Second tuple empty
GMP_TUPLE_CONCAT((1, 2, 3), ()) // expands to (1, 2, 3)
// Both tuples empty
GMP_TUPLE_CONCAT((), ()) // expands to ()
// Mixed sizes
GMP_TUPLE_CONCAT((a), (b, c, d)) // expands to (a, b, c, d)
GMP_TUPLE_CONCAT((a, b, c), (d)) // expands to (a, b, c, d)
#define GMP_TUPLE_CONCAT(tup_a, tup_b)
Concatenate two tuples into a single tuple.
Definition macro.hpp:1099
See also
GMP_TUPLE_APPEND for adding a single element to the end
GMP_TUPLE_PREPEND for adding a single element to the beginning
GMP_TUPLE_SLICE for extracting a subsequence from a tuple

Definition at line 1099 of file macro.hpp.

◆ GMP_TUPLE_EMPTY

#define GMP_TUPLE_EMPTY (   tup)

This macro determines whether a tuple has zero elements.

Parameters
tupThe tuple enclosed in parentheses, e.g., ()
Returns
1 if the tuple is empty, 0 otherwise
Example
#define EMPTY_TUPLE ()
#define NON_EMPTY_TUPLE (a, b, c)
int is_empty1 = GMP_TUPLE_EMPTY(EMPTY_TUPLE); // expands to 1
int is_empty2 = GMP_TUPLE_EMPTY(NON_EMPTY_TUPLE); // expands to 0
int is_empty3 = GMP_TUPLE_EMPTY((x)); // expands to 0
#define GMP_TUPLE_EMPTY(tup)
Check if a tuple is empty.
Definition macro.hpp:1148

Definition at line 1148 of file macro.hpp.

◆ GMP_TUPLE_PREPEND

#define GMP_TUPLE_PREPEND (   tup,
 
)

This macro creates a new tuple by adding the element x to the beginning of the input tuple tup. It handles both empty and non-empty tuples correctly.

Parameters
tupThe input tuple (may be empty)
xThe element to prepend to the tuple
Returns
A new tuple with x added at the beginning
Note
If tup is empty, the result is a single-element tuple containing x.
This macro ensures proper parentheses handling for empty tuples.
Example
// Prepend to non-empty tuple
GMP_TUPLE_PREPEND((b, c, d), a) // expands to (a, b, c, d)
// Prepend to empty tuple
GMP_TUPLE_PREPEND((), x) // expands to (x)
// Chaining prepend operations
GMP_TUPLE_PREPEND(GMP_TUPLE_PREPEND((c, d), b), a) // expands to (a, b, c, d)
#define GMP_TUPLE_PREPEND(tup, x)
Prepend an element to the beginning of a tuple.
Definition macro.hpp:1055
See also
GMP_TUPLE_APPEND for adding elements to the end
GMP_TUPLE_CONCAT for concatenating two tuples

Definition at line 1055 of file macro.hpp.

◆ GMP_TUPLE_SIZE

#define GMP_TUPLE_SIZE (   tup)

This macro calculates the size (number of elements) of a tuple.

Parameters
tupThe tuple enclosed in parentheses, e.g., (a, b, c)
Returns
The number of elements in the tuple as a macro integer
Example
#define TUPLE_1 (apple, banana, cherry)
#define TUPLE_2 (x, y)
int size1 = GMP_TUPLE_SIZE(TUPLE_1); // expands to 3
int size2 = GMP_TUPLE_SIZE(TUPLE_2); // expands to 2
int size3 = GMP_TUPLE_SIZE(()); // expands to 0 (empty tuple)
#define GMP_TUPLE_SIZE(tup)
Calculate the number of elements in a tuple.
Definition macro.hpp:1126

Definition at line 1126 of file macro.hpp.

◆ GMP_TUPLE_SKIP

#define GMP_TUPLE_SKIP (   count,
  tup 
)

This macro creates a new tuple by removing the first 'count' elements from the input tuple. It uses GMP_WHILE to iteratively process the tuple elements, building up the result by appending elements that should not be skipped.

The algorithm works as follows:

  1. State: (current_index, input_tuple, result_tuple)
  2. Continue while: current_index != size_of_input_tuple (i.e., haven't processed all elements)
  3. Operation for each iteration:
    • If current_index >= count: append current element to result
    • Increment current_index
Parameters
countNumber of elements to skip from the beginning (0-based)
tupInput tuple enclosed in parentheses
Returns
New tuple containing elements from index 'count' to the end
Note
If count >= tuple size, returns an empty tuple.
If count == 0, returns the original tuple.
The implementation uses GMP_EQUAL_INT_INDEPENDENT for comparison, making it independent of other comparison mechanisms.
Example
// Skip first 2 elements
GMP_TUPLE_SKIP(2, (a, b, c, d, e)) // expands to (c, d, e)
// Skip 0 elements (return original)
GMP_TUPLE_SKIP(0, (a, b, c, d, e)) // expands to (a, b, c, d, e)
// Skip all elements
GMP_TUPLE_SKIP(5, (a, b, c, d, e)) // expands to ()
// Skip more than exist (empty result)
GMP_TUPLE_SKIP(10, (a, b, c, d, e)) // expands to ()
#define GMP_TUPLE_SKIP(count, tup)
Skip the first 'count' elements from a tuple and return the remaining elements.
Definition macro.hpp:1193
See also
GMP_TUPLE_TAKE for taking the first N elements
GMP_TUPLE_SLICE for selecting a range of elements

Definition at line 1193 of file macro.hpp.

◆ GMP_TUPLE_TAKE

#define GMP_TUPLE_TAKE (   count,
  tup 
)

This macro creates a new tuple containing the first 'count' elements from the input tuple tup. If 'count' exceeds the tuple size, the entire tuple is returned as a fallback behavior.

Parameters
countNumber of elements to take from the beginning (non-negative)
tupInput tuple
Returns
A new tuple containing the first 'count' elements
Note
If count == 0, returns an empty tuple.
If count >= GMP_TUPLE_SIZE(tup), returns the entire tuple.
The implementation builds the result by prepending elements in reverse order and then reversing them, which is efficient for macro processing.
Example
// Take first 3 elements
GMP_TUPLE_TAKE(3, (a, b, c, d, e)) // expands to (a, b, c)
// Take first element
GMP_TUPLE_TAKE(1, (x, y, z)) // expands to (x)
// Take zero elements
GMP_TUPLE_TAKE(0, (a, b, c)) // expands to ()
// Take more than available (returns full tuple)
GMP_TUPLE_TAKE(10, (a, b, c)) // expands to (a, b, c)
// Take all elements exactly
GMP_TUPLE_TAKE(3, (a, b, c)) // expands to (a, b, c)
#define GMP_TUPLE_TAKE(count, tup)
Take the first 'count' elements from a tuple.
Definition macro.hpp:1258
Error Handling
If 'count' is greater than the tuple size, the macro falls back to returning the entire tuple. This is considered a "soft error" rather than a compile-time failure, as it may be useful in some metaprogramming contexts.
Warning
For precise error checking in safety-critical contexts, consider validating 'count' before calling this macro.
See also
GMP_TUPLE_SKIP for taking elements from the end (complementary operation)
GMP_TUPLE_SLICE for taking a range of elements
GMP_TUPLE_APPEND for adding elements to the end
GMP_TUPLE_PREPEND for adding elements to the beginning

Definition at line 1258 of file macro.hpp.

◆ GMP_WHILE

#define GMP_WHILE (   pred,
  op,
  args 
)
Parameters
predA macro that receives args and returns a truthy preprocessor value.
opA macro that transforms args for the next iteration.
argsThe initial state passed to pred and op.

Definition at line 1589 of file macro.hpp.

◆ GMP_XOR

#define GMP_XOR (   a,
 
)

This macro computes the logical XOR of two boolean values a and b. XOR returns true (1) if exactly one of the inputs is true, false (0) otherwise.

Truth table:

Parameters
aFirst boolean value (0 or non-zero)
bSecond boolean value (0 or non-zero)
Returns
1 if exactly one of a or b is non-zero, 0 otherwise
Note
Non-zero values are treated as true (1).
Example
GMP_XOR(0, 0) // expands to 0
GMP_XOR(0, 1) // expands to 1
GMP_XOR(1, 0) // expands to 1
GMP_XOR(1, 1) // expands to 0
GMP_XOR(GMP_BOOL(5), 0) // expands to 1 (5 is non-zero)
GMP_XOR(GMP_BOOL(3), GMP_BOOL(7)) // expands to 0 (both non-zero)
#define GMP_XOR(a, b)
Logical XOR (exclusive OR) operation for two boolean values.
Definition macro.hpp:3036
XOR Properties
See also
GMP_AND for logical AND operation
GMP_OR for logical OR operation
GMP_NOT for logical NOT operation

Definition at line 3036 of file macro.hpp.