11#include <range/v3/algorithm/copy_n.hpp>
12#include <range/v3/algorithm/for_each.hpp>
13#include <range/v3/algorithm/reverse.hpp>
14#include <range/v3/iterator/access.hpp>
15#include <range/v3/iterator/concepts.hpp>
16#include <range/v3/iterator/traits.hpp>
17#include <range/v3/range/access.hpp>
18#include <range/v3/range/concepts.hpp>
19#include <range/v3/range/conversion.hpp>
20#include <range/v3/range/traits.hpp>
21#include <range/v3/range_fwd.hpp>
22#include <range/v3/utility/semiregular_box.hpp>
23#include <range/v3/view/adaptor.hpp>
24#include <range/v3/view/all.hpp>
25#include <range/v3/view/concat.hpp>
26#include <range/v3/view/facade.hpp>
27#include <range/v3/view/for_each.hpp>
28#include <range/v3/view/join.hpp>
29#include <range/v3/view/single.hpp>
30#include <range/v3/view/transform.hpp>
31#include <range/v3/view/view.hpp>
42template <EndiannessKind To, ranges::range Range>
45 ranges::reverse(range);
49template <
template <std::
size_t, EndiannessKind>
typename SizedTo, std::size_t Size>
52 template <EndiannessKind Endianness>
70template <
template <EndiannessKind>
typename To,
EndiannessKind Endianness, ranges::range Range>
71 requires(std::is_trivially_copyable_v<ranges::range_value_t<Range>>)
73 To<Endianness> buffer{};
75 if constexpr (
requires(To<Endianness> rng, std::size_t new_size) { rng.resize(new_size); }) {
76 auto size =
sizeof(ranges::range_value_t<Range>) * range.size();
80 auto copy_next = [buf_iter = ranges::begin(buffer)](
const auto& val)
mutable {
81 auto byte_array = std::bit_cast<std::array<
Byte,
sizeof(val)>>(val);
83 ranges::copy_n(byte_array.begin(), byte_array.size(), buf_iter);
84 buf_iter += byte_array.size();
87 ranges::for_each(range, copy_next);
96template <std::same_as<NativeByteVector> NativeTo, ranges::range Range>
97 requires(std::is_trivially_copyable_v<ranges::range_value_t<Range>>)
107template <
template <std::
size_t, EndiannessKind>
typename SizedTo, std::size_t Size,
EndiannessKind Endianness,
109 requires(std::is_trivially_copyable_v<ranges::range_value_t<Range>>)
111 return to_bytes<detail::partial_bytearray_spec<SizedTo, Size>::template templated, Endianness>(range);
117template <
template <std::
size_t, EndiannessKind>
typename SizedTo,
EndiannessKind Endianness, ranges::range Range>
118 requires(std::is_trivially_copyable_v<ranges::range_value_t<Range>> &&
119 std::is_trivially_copyable_v<ranges::range_value_t<Range>>)
122 " to infer size of ByteArray");
133template <
template <std::
size_t>
typename NativeSizedTo, std::size_t Size, ranges::range Range>
135 std::is_trivially_copyable_v<ranges::range_value_t<Range>>)
143template <
template <std::
size_t>
typename NativeSizedTo, ranges::range Range>
145 std::is_trivially_copyable_v<ranges::range_value_t<Range>>)
148 " to infer size of NativeByteArray");
162 To<Endianness> buffer{};
164 if constexpr (
requires(To<Endianness> rng, std::size_t new_size) { rng.resize(new_size); }) {
165 constexpr auto size = (
sizeof(Ts) + ...);
169 auto copy_next = [buf_iter = ranges::begin(buffer)](
const auto& val)
mutable {
170 auto byte_array = std::bit_cast<std::array<
Byte,
sizeof(val)>>(val);
172 ranges::copy_n(byte_array.begin(), byte_array.size(), buf_iter);
173 buf_iter += byte_array.size();
176 (copy_next(values), ...);
184template <std::same_as<NativeByteVector> NativeTo, C<std::is_trivially_copyable>... Ts>
192template <
template <std::
size_t, EndiannessKind>
typename SizedTo, std::size_t Size,
EndiannessKind Endianness,
195 return to_bytes<detail::partial_bytearray_spec<SizedTo, Size>::template templated, Endianness>(values...);
201template <
template <std::
size_t, EndiannessKind>
typename SizedTo,
EndiannessKind Endianness,
203constexpr auto to_bytes(
const Ts&... values) {
204 constexpr auto size = (0 + ... +
sizeof(Ts));
232template <EndiannessKind Endianness = EndiannessKind::Native>
More user-friendly interface wrapper for a byte-like integral.
Definition byte.hpp:18
Definition static_size.hpp:13
constexpr void maybe_reverse_endianness(Range &range)
Definition bit_casts.hpp:43
Definition asm_buffer.hpp:20
consteval std::size_t get_static_size()
Definition static_size.hpp:19
EndiannessKind
Definition os.hpp:47
constexpr auto to_bytes(const Range &range)
Reinterpret a range of trivially copyable values as a ByteVector of specified endianness,...
Definition bit_casts.hpp:72
constexpr decltype(auto) as_bytes()
callable providing a view adaptor to reinterpret a range of trivially copyable values as bytes.
Definition bit_casts.hpp:233
ByteArray< N, EndiannessKind::Native > NativeByteArray
Definition byte_array.hpp:86
Definition bit_casts.hpp:51
SizedTo< Size, Endianness > templated
Definition bit_casts.hpp:53
#define C
Definition test_macros.hpp:149