Skip to content

Commit

Permalink
Add a tuple manipulation header
Browse files Browse the repository at this point in the history
  • Loading branch information
agagniere committed Oct 4, 2024
1 parent d95e8a9 commit ed09515
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "blackmagic",
.version = "0.2.0",
.version = "0.3.0",
.paths = .{ "build.zig", "build.zig.zon", "include", "README.md", "LICENSE" },
}
26 changes: 26 additions & 0 deletions include/blackmagic/tuple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "blackmagic/token.h" // CONCAT

/**
* @file
* Manipulate tuples
*/

/** Extract the first element of a tuple */
#define TUPLE_FIRST(A, ...) A
/** Extract the second element of a tuple */
#define TUPLE_SECOND(A, B, ...) B
/** Extract the third element of a tuple */
#define TUPLE_THIRD(A, B, C, ...) C

/** Extract the Nth element of a tuple */
#define TUPLE_GET(N, TUPLE) CONCAT(TUPLE_GET_, N) TUPLE

#define TUPLE_GET_0(A, ...) A
#define TUPLE_GET_1(A,B, ...) B
#define TUPLE_GET_2(A,B,C, ...) C
#define TUPLE_GET_3(A,B,C,D, ...) D
#define TUPLE_GET_4(A,B,C,D,E, ...) E
#define TUPLE_GET_5(A,B,C,D,E,F, ...) F
#define TUPLE_GET_6(A,B,C,D,E,F,G, ...) G

0 comments on commit ed09515

Please sign in to comment.