#ifndef RFL_CONCEPTS_HPP_ #define RFL_CONCEPTS_HPP_ #include #include #include #include #include namespace rfl::concepts { /// Concept for byte-like types that can be used in contiguous containers /// Includes char, signed char, unsigned char, std::byte, and uint8_t template concept ByteLike = std::same_as || std::same_as || std::same_as || std::same_as || std::same_as; /// Concept for containers with a contiguous sequence of byte-like types /// Requires: /// - Container has a value_type that is byte-like /// - Container provides data() method returning a pointer to contiguous memory /// - Container provides size() method returning the number of elements /// - Container supports range-based for loops (begin/end) template concept ContiguousByteContainer = requires(const Container& c) { typename Container::value_type; { c.data() } -> std::convertible_to; { c.size() } -> std::convertible_to; { c.begin() } -> std::input_iterator; { c.end() } -> std::input_iterator; requires ByteLike; requires std::contiguous_iterator; }; /// Concept for mutable containers with a contiguous sequence of byte-like types /// Extends ContiguousByteContainer with mutable access requirements template concept MutableContiguousByteContainer = ContiguousByteContainer && requires(Container& c) { { c.data() } -> std::convertible_to; { c.begin() } -> std::output_iterator; { c.end() } -> std::output_iterator; }; /// Concept for back-insertable byte containers (like std::vector) /// Useful for containers that can grow dynamically during serialization template concept BackInsertableByteContainer = ContiguousByteContainer && requires(Container& c, typename Container::value_type v) { c.push_back(v); c.reserve(std::size_t{}); { c.capacity() } -> std::convertible_to; }; /// Concept for byte spans or views (read-only, non-owning containers) /// Includes std::span, std::string_view when used with char /// data, etc. template concept ByteSpanLike = ContiguousByteContainer && std::is_trivially_copyable_v && std::is_trivially_destructible_v; } // namespace rfl::concepts #endif // RFL_CONCEPTS_HPP_