diff --git a/include/stdx/byterator.hpp b/include/stdx/byterator.hpp index 8c643a9..06f7782 100644 --- a/include/stdx/byterator.hpp +++ b/include/stdx/byterator.hpp @@ -188,20 +188,32 @@ template class byterator { ptr += sizeof(R); } - [[nodiscard]] auto peeku8() { return peek(); } - [[nodiscard]] auto readu8() { return read(); } + template [[nodiscard]] auto peeku8() { + return peek(); + } + template [[nodiscard]] auto readu8() { + return read(); + } template [[nodiscard]] auto writeu8(V &&v) { return write(static_cast(std::forward(v))); } - [[nodiscard]] auto peeku16() { return peek(); } - [[nodiscard]] auto readu16() { return read(); } + template [[nodiscard]] auto peeku16() { + return peek(); + } + template [[nodiscard]] auto readu16() { + return read(); + } template [[nodiscard]] auto writeu16(V &&v) { return write(static_cast(std::forward(v))); } - [[nodiscard]] auto peeku32() { return peek(); } - [[nodiscard]] auto readu32() { return read(); } + template [[nodiscard]] auto peeku32() { + return peek(); + } + template [[nodiscard]] auto readu32() { + return read(); + } template [[nodiscard]] auto writeu32(V &&v) { return write(static_cast(std::forward(v))); } diff --git a/test/byterator.cpp b/test/byterator.cpp index 7fa34ec..1353ef3 100644 --- a/test/byterator.cpp +++ b/test/byterator.cpp @@ -258,3 +258,21 @@ TEST_CASE("write enum (constrained size)", "[byterator]") { CHECK(a[0] == stdx::to_be(0x0302)); CHECK((i == j)); } + +TEST_CASE("peek enum (constrained size alias)", "[byterator]") { + auto const a = std::array{stdx::to_be(0x0102), + stdx::to_be(0x0304)}; + auto i = stdx::byterator{std::begin(a)}; + static_assert(std::is_same_v); + CHECK(i.peeku8() == E2::A); +} + +TEST_CASE("read enum (constrained size alias)", "[byterator]") { + auto const a = std::array{stdx::to_be(0x0102), + stdx::to_be(0x0304)}; + auto i = stdx::byterator{std::begin(a)}; + auto j = std::next(i); + static_assert(std::is_same_v); + CHECK(i.readu8() == E2::A); + CHECK((i == j)); +}