11#pragma once
22#include " ../utility/assert.h"
3+ #include " ../utility/meta.h"
4+ #include " ../utility/parameter.h"
35
46#include " ../stream/serialize_traits.h"
5- #include " ../stream/bit_reader.h"
6- #include " ../stream/bit_writer.h"
77
88#include " ../traits/integral_traits.h"
99
@@ -23,19 +23,23 @@ namespace bitstream
2323 struct serialize_traits <T, typename std::enable_if_t <std::is_enum_v<T>>>
2424 {
2525 using value_type = std::underlying_type_t <T>;
26-
27- static bool serialize (bit_writer& writer, T value, value_type min = 0 , value_type max = (std::numeric_limits<value_type>::max)()) noexcept
26+
27+ template <typename Stream>
28+ typename utility::is_writing_t <Stream>
29+ static serialize (Stream& writer, T value, value_type min = 0 , value_type max = (std::numeric_limits<value_type>::max)()) noexcept
2830 {
2931 value_type unsigned_value = static_cast <value_type>(value);
3032
31- return writer.serialize <value_type>(unsigned_value, min, max);
33+ return writer.template serialize <value_type>(unsigned_value, min, max);
3234 }
3335
34- static bool serialize (bit_reader& reader, T& value, value_type min = 0 , value_type max = (std::numeric_limits<value_type>::max)()) noexcept
36+ template <typename Stream>
37+ typename utility::is_reading_t <Stream>
38+ static serialize (Stream& reader, T& value, value_type min = 0 , value_type max = (std::numeric_limits<value_type>::max)()) noexcept
3539 {
3640 value_type unsigned_value;
3741
38- BS_ASSERT (reader.serialize <value_type>(unsigned_value, min, max));
42+ BS_ASSERT (reader.template serialize <value_type>(unsigned_value, min, max));
3943
4044 value = static_cast <T>(unsigned_value);
4145
@@ -52,18 +56,22 @@ namespace bitstream
5256 using value_type = std::underlying_type_t <T>;
5357 using bound_type = bounded_int<value_type, Min, Max>;
5458
55- static bool serialize (bit_writer& writer, T value) noexcept
59+ template <typename Stream>
60+ typename utility::is_writing_t <Stream>
61+ static serialize (Stream& writer, T value) noexcept
5662 {
5763 value_type unsigned_value = static_cast <value_type>(value);
5864
59- return writer.serialize <bound_type>(unsigned_value);
65+ return writer.template serialize <bound_type>(unsigned_value);
6066 }
6167
62- static bool serialize (bit_reader& reader, T& value) noexcept
68+ template <typename Stream>
69+ typename utility::is_reading_t <Stream>
70+ static serialize (Stream& reader, T& value) noexcept
6371 {
6472 value_type unsigned_value;
6573
66- BS_ASSERT (reader.serialize <bound_type>(unsigned_value));
74+ BS_ASSERT (reader.template serialize <bound_type>(unsigned_value));
6775
6876 value = static_cast <T>(unsigned_value);
6977
0 commit comments