Skip to content

Commit

Permalink
Added support for plain array.
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalz800 committed Dec 25, 2021
1 parent 5d9a594 commit 36904a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/src/test_data_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ TEST(data_sources, stdarray)
EXPECT_EQ(v, (std::vector{1,2,3,4}));
}


TEST(data_sources, array)
{
std::byte data[128];
auto [in, out] = zpp::bits::in_out(data);
out(std::vector{1,2,3,4}).or_throw();

EXPECT_EQ(hexlify(std::span{std::data(data), out.position()}),
"04000000"
"01000000"
"02000000"
"03000000"
"04000000");

std::vector<int> v;
in(v).or_throw();

EXPECT_EQ(v, (std::vector{1,2,3,4}));
}

TEST(data_sources, array_over_span)
{
std::byte data[128];
Expand Down
6 changes: 6 additions & 0 deletions zpp_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,9 @@ out(Type &) -> out<Type>;
template <typename Type>
out(Type &&) -> out<Type>;

template <typename Type, std::size_t Size>
out(Type (&)[Size]) -> out<std::span<Type>>;

template <concepts::byte_view ByteView = std::vector<std::byte>>
class in
{
Expand Down Expand Up @@ -1578,6 +1581,9 @@ class in
std::size_t m_position{};
};

template <typename Type, std::size_t Size>
in(Type (&)[Size]) -> in<std::span<Type>>;

constexpr auto input(auto && view, auto &&... option)
{
return in(std::forward<decltype(view)>(view),
Expand Down

0 comments on commit 36904a7

Please sign in to comment.