From 06366839aa6fc10491e66fc64944e3579d15d593 Mon Sep 17 00:00:00 2001 From: Nik Date: Wed, 12 Jul 2023 00:13:02 +0200 Subject: [PATCH] includes/std: Added std::ByteSizedArray --- includes/std/array.pat | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/std/array.pat b/includes/std/array.pat index 517baa9..c4fa350 100644 --- a/includes/std/array.pat +++ b/includes/std/array.pat @@ -1,5 +1,7 @@ #pragma once +#include + /*! The array library contains a helper type to make it easier to create multi-dimensional arrays and pass arrays to functions as parameters. @@ -10,10 +12,30 @@ namespace std { /** Simple one dimensional array wrapper @tparam T The array types - @tparam Size Size of the array + @tparam Size Number of entries in the array */ struct Array { T data[Size] [[inline]]; - }; + } [[format("std::impl::format_array")]]; + + /** + Simple array wrapper for an array with a size in bytes + @tparam T The array types + @tparam NumBytes Number of bytes the array contains + */ + struct ByteSizedArray { + u64 startAddress = $; + T array[while($ - startAddress < NumBytes)] [[inline]]; + + std::assert($ - startAddress == NumBytes, "Not enough bytes available to fit a whole number of types"); + } [[format("std::impl::format_array")]]; + + namespace impl { + + fn format_array(ref auto array) { + return "[ ... ]"; + }; + + } }