From d5559ecafdbafa0fd6b46b130f2e91fb5d443cfc Mon Sep 17 00:00:00 2001 From: Ero Mrinin <47291495+EroMrinin134@users.noreply.github.com> Date: Sun, 6 Jul 2025 04:08:59 +0400 Subject: [PATCH] Tuple update (#2235) * 'next_float' macro patch More optimized implementation. * tuple-type update * U suffix in 'next_float' * Do not add triplet, quadruplet, keep Tuple but deprecate. Add unpack --------- Co-authored-by: Christoffer Lerno --- lib/std/collections/tuple.c3 | 27 ++++++++++++++++++++++++--- lib/std/math/random.c3 | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/std/collections/tuple.c3 b/lib/std/collections/tuple.c3 index 597605e35..053a52034 100644 --- a/lib/std/collections/tuple.c3 +++ b/lib/std/collections/tuple.c3 @@ -1,11 +1,24 @@ -module std::collections::tuple{Type1, Type2}; +module std::collections::pair{Type1, Type2}; -struct Tuple +struct Pair { Type1 first; Type2 second; } +<* + @param [&out] a + @param [&out] b + @require $assignable(self.first, $typeof(*a)) : "You cannot assign the first value to a" + @require $assignable(self.second, $typeof(*b)) : "You cannot assign the second value to b" +*> + +macro void Pair.unpack(&self, a, b) +{ + *a = self.first; + *b = self.second; +} + module std::collections::triple{Type1, Type2, Type3}; struct Triple @@ -13,4 +26,12 @@ struct Triple Type1 first; Type2 second; Type3 third; -} \ No newline at end of file +} + +module std::collections::tuple{Type1, Type2}; + +struct Tuple @deprecated("Use 'Pair' instead") +{ + Type1 first; + Type2 second; +} diff --git a/lib/std/math/random.c3 b/lib/std/math/random.c3 index ee9288566..e3bbf4034 100644 --- a/lib/std/math/random.c3 +++ b/lib/std/math/random.c3 @@ -117,7 +117,7 @@ macro bool next_bool(random) *> macro float next_float(random) { - uint val = random.next_int() & (1 << 24 - 1); + uint val = random.next_int() & (1U << 24 - 1); return val * 0x1.0p-24f; }