io/Reader: add method ReadT()

This commit is contained in:
Max Kellermann 2023-10-05 10:33:51 +02:00
parent b81cac3305
commit 496184b1bc
1 changed files with 8 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#define READER_HXX
#include <cstddef>
#include <type_traits>
/**
* An interface that can read bytes from a stream until the stream
@ -26,6 +27,13 @@ public:
*/
[[gnu::nonnull]]
virtual std::size_t Read(void *data, std::size_t size) = 0;
template<typename T>
requires std::is_standard_layout_v<T> && std::is_trivially_copyable_v<T>
void ReadT(T &dest) {
// TODO check return value
Read(&dest, sizeof(dest));
}
};
#endif