aboutsummaryrefslogtreecommitdiff
path: root/c/data.h
diff options
context:
space:
mode:
Diffstat (limited to 'c/data.h')
-rw-r--r--c/data.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/c/data.h b/c/data.h
index 6d6edd3..da8d108 100644
--- a/c/data.h
+++ b/c/data.h
@@ -123,7 +123,8 @@ struct FileView
}
/* Access element by index, performing bounds check and, if
- * applicable for T, version validation. */
+ * applicable for T, version validation as well as
+ * initialization, if needed. */
T& At(size_t i)
{
if (i >= c)
@@ -131,9 +132,13 @@ struct FileView
T& t = view[i];
- if constexpr (HasVersion<T>)
- if (t.version != Version<T>)
+ if constexpr (HasVersion<T>) {
+ if (t.version == 0) {
+ T t_;
+ memcpy(&t, &t_, sizeof(T));
+ } else if (t.version != Version<T>)
throw std::runtime_error("invalid struct version");
+ }
/* TODO: Use a custom exception type that informs the
* user of possible data corruption. */