From 5d35a3e92d5f58fd5d77d4f14ce855811b3db9b8 Mon Sep 17 00:00:00 2001 From: Jan Mrna Date: Thu, 16 Oct 2025 18:01:29 +0200 Subject: [PATCH] vec class: structured binding support --- cpp/src/math.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cpp/src/math.hpp b/cpp/src/math.hpp index be6e290..706d32d 100644 --- a/cpp/src/math.hpp +++ b/cpp/src/math.hpp @@ -265,6 +265,21 @@ public: return vec(m_Array); } + // Structured binding support for N == 2 + template + const T& get() const + requires(N == 2 && I < 2) + { + return m_Array[I]; + } + + template + T& get() + requires(N == 2 && I < 2) + { + return m_Array[I]; + } + private: std::array m_Array; }; @@ -409,3 +424,25 @@ public: private: std::array m_Array; }; + +// Structured binding support for vec +namespace std { + template + struct tuple_size> : integral_constant {}; + + template + struct tuple_element> { + using type = T; + }; +} + +// ADL-based get for structured bindings +template +const T& get(const vec& v) { + return v.template get(); +} + +template +T& get(vec& v) { + return v.template get(); +}