Skip to content

Instantly share code, notes, and snippets.

@derrickturk
Created February 6, 2024 22:53
Show Gist options
  • Save derrickturk/2e26b18de7f075b0b069bae63ec24df8 to your computer and use it in GitHub Desktop.
Save derrickturk/2e26b18de7f075b0b069bae63ec24df8 to your computer and use it in GitHub Desktop.
X-macros
#include <cstdio>
const std::size_t num_buttons = 16;
const std::size_t total_buttons = num_buttons + 4;
#define FOR_EACH_NUMBER(n) "Button " #n,
const char* english[total_buttons] = {
#include "numbers.def"
"Hat Up",
"Hat Down",
"Hat Left",
"Hat Right",
};
#undef FOR_EACH_NUMBER
#define FOR_EACH_NUMBER(n) "Knopf " #n,
const char* german[total_buttons] = {
#include "numbers.def"
"Hut Hinten",
"Hut Vorne",
"Hut Links",
"Hut Rechts",
};
#undef FOR_EACH_NUMBER
int main()
{
for (const auto& e: english)
puts(e);
for (const auto& g: german)
puts(g);
}
FOR_EACH_NUMBER(1)
FOR_EACH_NUMBER(2)
FOR_EACH_NUMBER(3)
FOR_EACH_NUMBER(4)
FOR_EACH_NUMBER(5)
FOR_EACH_NUMBER(6)
FOR_EACH_NUMBER(7)
FOR_EACH_NUMBER(8)
FOR_EACH_NUMBER(9)
FOR_EACH_NUMBER(10)
FOR_EACH_NUMBER(11)
FOR_EACH_NUMBER(12)
FOR_EACH_NUMBER(13)
FOR_EACH_NUMBER(14)
FOR_EACH_NUMBER(15)
FOR_EACH_NUMBER(16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment