Applied the byte containers to all byte formats (#474)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-08-04 21:45:27 +02:00
committed by GitHub
parent 07cf980a00
commit 93e41778ca
9 changed files with 133 additions and 105 deletions
+43 -30
View File
@@ -1,8 +1,8 @@
#include <vector>
#include <array>
#include <string>
#include <cassert>
#include <rfl/concepts.hpp>
#include <string>
#include <vector>
#include "write_and_read.hpp"
@@ -15,40 +15,53 @@ TEST(generic, test_byte_container_concepts) {
std::array<std::uint8_t, 4> arr_uint8{1, 2, 3, 4};
std::string str_data{"hello"};
std::string_view str_view{"world"};
std::array<std::byte, 5> arr_byte{std::byte{5}, std::byte{4}, std::byte{3}, std::byte{2}, std::byte{1}};
std::array<std::byte, 5> arr_byte{std::byte{5}, std::byte{4}, std::byte{3},
std::byte{2}, std::byte{1}};
std::span<std::byte> byte_span = arr_byte;
// Test with concepts
static_assert(rfl::ByteLike<std::uint8_t>);
static_assert(rfl::ByteLike<char>);
static_assert(rfl::ByteLike<unsigned char>);
static_assert(rfl::ByteLike<std::byte>);
static_assert(!rfl::ByteLike<int>);
static_assert(!rfl::ByteLike<float>);
static_assert(rfl::concepts::ByteLike<std::uint8_t>);
static_assert(rfl::concepts::ByteLike<char>);
static_assert(rfl::concepts::ByteLike<unsigned char>);
static_assert(rfl::concepts::ByteLike<std::byte>);
static_assert(!rfl::concepts::ByteLike<int>);
static_assert(!rfl::concepts::ByteLike<float>);
static_assert(rfl::ContiguousByteContainer<decltype(vec_uint8)>);
static_assert(rfl::ContiguousByteContainer<decltype(vec_char)>);
static_assert(rfl::ContiguousByteContainer<decltype(arr_uint8)>);
static_assert(rfl::ContiguousByteContainer<decltype(str_data)>);
static_assert(rfl::ContiguousByteContainer<decltype(str_view)>);
static_assert(rfl::ContiguousByteContainer<decltype(arr_byte)>);
static_assert(rfl::ContiguousByteContainer<decltype(byte_span)>);
static_assert(rfl::concepts::ContiguousByteContainer<decltype(vec_uint8)>);
static_assert(rfl::concepts::ContiguousByteContainer<decltype(vec_char)>);
static_assert(rfl::concepts::ContiguousByteContainer<decltype(arr_uint8)>);
static_assert(rfl::concepts::ContiguousByteContainer<decltype(str_data)>);
static_assert(rfl::concepts::ContiguousByteContainer<decltype(str_view)>);
static_assert(rfl::concepts::ContiguousByteContainer<decltype(arr_byte)>);
static_assert(rfl::concepts::ContiguousByteContainer<decltype(byte_span)>);
static_assert(rfl::MutableContiguousByteContainer<decltype(vec_uint8)>);
static_assert(rfl::MutableContiguousByteContainer<decltype(vec_char)>);
static_assert(rfl::MutableContiguousByteContainer<decltype(arr_uint8)>);
static_assert(rfl::MutableContiguousByteContainer<decltype(str_data)>);
static_assert(!rfl::MutableContiguousByteContainer<decltype(str_view)>);
static_assert(rfl::MutableContiguousByteContainer<decltype(arr_byte)>);
static_assert(rfl::MutableContiguousByteContainer<decltype(byte_span)>);
static_assert(
rfl::concepts::MutableContiguousByteContainer<decltype(vec_uint8)>);
static_assert(
rfl::concepts::MutableContiguousByteContainer<decltype(vec_char)>);
static_assert(
rfl::concepts::MutableContiguousByteContainer<decltype(arr_uint8)>);
static_assert(
rfl::concepts::MutableContiguousByteContainer<decltype(str_data)>);
static_assert(
!rfl::concepts::MutableContiguousByteContainer<decltype(str_view)>);
static_assert(
rfl::concepts::MutableContiguousByteContainer<decltype(arr_byte)>);
static_assert(
rfl::concepts::MutableContiguousByteContainer<decltype(byte_span)>);
static_assert(rfl::BackInsertableByteContainer<decltype(vec_uint8)>);
static_assert(rfl::BackInsertableByteContainer<decltype(vec_char)>);
static_assert(!rfl::BackInsertableByteContainer<decltype(arr_uint8)>);
static_assert(rfl::BackInsertableByteContainer<decltype(str_data)>);
static_assert(!rfl::BackInsertableByteContainer<decltype(str_view)>);
static_assert(!rfl::BackInsertableByteContainer<decltype(arr_byte)>);
static_assert(!rfl::BackInsertableByteContainer<decltype(byte_span)>);
static_assert(
rfl::concepts::BackInsertableByteContainer<decltype(vec_uint8)>);
static_assert(rfl::concepts::BackInsertableByteContainer<decltype(vec_char)>);
static_assert(
!rfl::concepts::BackInsertableByteContainer<decltype(arr_uint8)>);
static_assert(rfl::concepts::BackInsertableByteContainer<decltype(str_data)>);
static_assert(
!rfl::concepts::BackInsertableByteContainer<decltype(str_view)>);
static_assert(
!rfl::concepts::BackInsertableByteContainer<decltype(arr_byte)>);
static_assert(
!rfl::concepts::BackInsertableByteContainer<decltype(byte_span)>);
}
} // namespace test_byte_container_concepts