mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +00:00
LibIPC: Add support for encoding and decoding Array<T, N>
Also add a note to the Concepts header that the reason we have all the strange concepts in place for container types is to work around the language limitation that we cannot partially specialize function templates.
This commit is contained in:
parent
e09bfc1a8c
commit
7e6918e14a
3 changed files with 33 additions and 0 deletions
|
@ -108,6 +108,18 @@ ErrorOr<File> decode(Decoder&);
|
|||
template<>
|
||||
ErrorOr<Empty> decode(Decoder&);
|
||||
|
||||
template<Concepts::Array T>
|
||||
ErrorOr<T> decode(Decoder& decoder)
|
||||
{
|
||||
T array {};
|
||||
auto size = TRY(decoder.decode_size());
|
||||
if (size != array.size())
|
||||
return Error::from_string_literal("Array size mismatch");
|
||||
for (size_t i = 0; i < array.size(); ++i)
|
||||
array[i] = TRY(decoder.decode<typename T::ValueType>());
|
||||
return array;
|
||||
}
|
||||
|
||||
template<Concepts::Vector T>
|
||||
ErrorOr<T> decode(Decoder& decoder)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue