[wpiutil] Change Struct to allow non-constexpr implementation (#5992)

This required changing the constant values (e.g. kSize) into functions
(e.g. GetSize()).

Fixed implementations of ForEachNested to be inline (as these are actually
templates).

Also added a ntcore Struct test.
This commit is contained in:
Peter Johnson
2023-12-02 23:36:44 -08:00
committed by GitHub
parent ca272de400
commit a583ca01e1
62 changed files with 812 additions and 450 deletions

View File

@@ -968,9 +968,16 @@ class StructLogEntry : public DataLogEntry {
* @param timestamp Time stamp (may be 0 to indicate now)
*/
void Append(const T& data, int64_t timestamp = 0) {
uint8_t buf[S::kSize];
S::Pack(buf, data);
m_log->AppendRaw(m_entry, buf, timestamp);
if constexpr (wpi::is_constexpr([] { S::GetSize(); })) {
uint8_t buf[S::GetSize()];
S::Pack(buf, data);
m_log->AppendRaw(m_entry, buf, timestamp);
} else {
wpi::SmallVector<uint8_t, 128> buf;
buf.resize_for_overwrite(S::GetSize());
S::Pack(buf, data);
m_log->AppendRaw(m_entry, buf, timestamp);
}
}
};