From d42eb123775b5ed627a41adedfce4f582cc27acc Mon Sep 17 00:00:00 2001
From: Patrick Wuttke
Date: Tue, 17 Feb 2026 10:25:09 +0100
Subject: [PATCH] Added variant_index utility trait.
---
source/mijin/util/variant.hpp | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/source/mijin/util/variant.hpp b/source/mijin/util/variant.hpp
index a3a98d5..da21699 100644
--- a/source/mijin/util/variant.hpp
+++ b/source/mijin/util/variant.hpp
@@ -20,6 +20,29 @@ inline constexpr bool variant_contains_v = false;
template
inline constexpr bool variant_contains_v> = mijin::is_any_type_v;
+
+template
+struct variant_index;
+
+template
+struct variant_index>
+{
+ static constexpr std::size_t getValue() noexcept
+ {
+ if constexpr (std::is_same_v) {
+ return 0;
+ }
+ else {
+ return variant_index>::getValue() + 1;
+ }
+ }
+
+ static constexpr std::size_t value = getValue();
+};
+
+template
+inline constexpr std::size_t variant_index_v = variant_index::value;
+
//
// public types
//