diff --git a/examples/tour.cpp b/examples/tour.cpp index 589f900..f1d45ce 100644 --- a/examples/tour.cpp +++ b/examples/tour.cpp @@ -39,6 +39,9 @@ int main() { std::println("std::get<1>(v): {}", std::get<1>(v)); auto [x, y, z] = v; std::println("Bindings: [{}, {}, {}]", x, y, z); + float x1{}, y1{}, z1{}; + v.unpack(x1, y1, z1); + std::println("Unpacked: {}, {}, {}", x1, y1, z1); // Let's mix and match! Vec<6> v3(v, 7, swizzle<"zy">(v2)); diff --git a/include/smath.hpp b/include/smath.hpp index c7a928e..81b6e6b 100644 --- a/include/smath.hpp +++ b/include/smath.hpp @@ -162,6 +162,16 @@ public: VEC_ACC(v, 2, 1) #undef VEC_ACC + template + constexpr void unpack_impl(std::index_sequence, + Args &...args) noexcept { + ((args = (*this)[Is]), ...); + } + + template constexpr void unpack(Args &...args) noexcept { + unpack_impl(std::index_sequence_for{}, args...); + } + // Unary constexpr auto operator-() noexcept -> Vec { Vec r{};