diff options
Diffstat (limited to 'c/data.h')
-rw-r--r-- | c/data.h | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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. */ |