summaryrefslogtreecommitdiffstats
path: root/prelude/slang-cpp-types.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-10-11 14:14:08 -0400
committerGitHub <noreply@github.com>2019-10-11 14:14:08 -0400
commit9c17d0be79834a8ebe2888aed8905bae355cb674 (patch)
treef0ebf7d256f43af686f63c6375f2a53bd12dc1a3 /prelude/slang-cpp-types.h
parentdeeb8647012fc6362f1bb33842cf0842e16f13b7 (diff)
Support for unbounded array of arrays (#1078)
* WIP: Unsized arrays on CPU. * unbounded-array-of-array working on CPU. * Remove some left over comments.
Diffstat (limited to 'prelude/slang-cpp-types.h')
-rw-r--r--prelude/slang-cpp-types.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/prelude/slang-cpp-types.h b/prelude/slang-cpp-types.h
index 2ba3fe19e..c8f6357a2 100644
--- a/prelude/slang-cpp-types.h
+++ b/prelude/slang-cpp-types.h
@@ -24,12 +24,20 @@ struct FixedArray
T m_data[SIZE];
};
-
-// Hmm... I guess a constant buffer should be unwrapped to be just a struct passed in
-/* template <typename T>
-struct ConstantBuffer
+// An array that has no specified size, becomes a 'Array'. This stores the size so it can potentially
+// do bounds checking.
+template <typename T>
+struct Array
{
-}; */
+ const T& operator[](size_t index) const { SLANG_PRELUDE_ASSERT(index < count); return data[index]; }
+ T& operator[](size_t index) { SLANG_PRELUDE_ASSERT(index < count); return data[index]; }
+
+ T* data;
+ size_t count;
+};
+
+/* Constant buffers become a pointer to the contained type, so ConstantBuffer<T> becomes T* in C++ code.
+*/
template <typename T, int COUNT>
struct Vector;