#include "binary-reader.inl" #include "binary-writer.inl" #include namespace floormat::Serialize { #if 0 template struct byte_array_iterator final { using iterator_category = std::forward_iterator_tag; using difference_type = std::ptrdiff_t; using value_type = char; using pointer = char*; using reference = char&; constexpr byte_array_iterator(char (&buf)[N]) : buf{&buf}, i{0} {} constexpr byte_array_iterator(char (&buf)[N], std::size_t i) : buf{&buf}, i{i} {} constexpr reference operator*() const { fm_assert(i < N); return (*buf)[i]; } constexpr pointer operator->() { fm_assert(i < N); return &(*buf)[i]; } constexpr byte_array_iterator& operator++() noexcept { i++; return *this; } constexpr byte_array_iterator operator++(int) noexcept { byte_array_iterator tmp = *this; ++(*this); return tmp; } friend constexpr bool operator==(const byte_array_iterator&& a, const byte_array_iterator&& b) noexcept = default; private: char (*buf)[N]; std::size_t i; }; template struct byte_array_iterator; #endif [[maybe_unused]] static constexpr bool test1() { constexpr std::array bytes = { 1, 2, 3, 4 }; auto x = binary_reader(bytes.cbegin(), bytes.cend()); return x.read() == 67305985; } static_assert(test1()); [[maybe_unused]] static constexpr bool test2() { constexpr std::array bytes = { 4, 3, 2, 1 }; auto r = binary_reader(bytes.cbegin(), bytes.cend()); const auto x = r.read(); r.assert_end(); return x == 16909060; } static_assert(test2()); using test3 = binary_reader::iterator>; static_assert(std::is_same_v() >> std::declval() )>); using test4 = binary_writer::iterator>; static_assert(std::is_same_v() << int() )>); [[maybe_unused]] static constexpr bool test5() { std::array bytes = {}; auto w = binary_writer(bytes.begin()); w << (char)0; w << (char)1; w << (char)2; w << (char)3; return bytes[0] == 0 && bytes[1] == 1 && bytes[2] == 2 && bytes[3] == 3; } static_assert(test5()); } // namespace floormat::Serialize