1 #include "at_each_aligned.hpp" 13 template <
typename... TFArgs>
16 template <
typename TFArg,
typename... TFArgRest>
19 static constexpr std::size_t byte_align =
sizeof(TFArg);
21 template <
typename TChar,
typename FApply,
typename... FApplyRest>
23 static TChar* step(TChar* first, TChar* last,
const FApply& apply,
const FApplyRest&... apply_rest)
25 if (reinterpret_cast<std::uintptr_t>(first) % byte_align == 0
26 && first + byte_align <= last
29 apply(reinterpret_cast<TFArg*>(first));
30 return first + byte_align;
42 static_assert(
sizeof(T) == 1,
"You must provide a single byte type to at_each_aligned");
44 template <
typename TChar,
typename FApply>
46 static TChar* step(TChar* first, TChar*,
const FApply& apply)
48 apply(reinterpret_cast<T*>(first));
53 template <
typename... TFArgs,
typename TChar,
typename... FApply>
54 void at_each_aligned(TChar* first, TChar* last, FApply&&... transform)
56 for ( ; first < last; )
64 template <
typename... TFArgs,
typename... FApply>
65 void at_each_aligned(
char* first,
char* last, FApply&&... transform)
67 detail::at_each_aligned<TFArgs...>(first, last, std::forward<FApply>(transform)...);
70 template <
typename... TFArgs,
typename... FApply>
71 void at_each_aligned(
const char* first,
const char* last, FApply&&... transform)
73 detail::at_each_aligned<
const TFArgs...>(first, last, std::forward<FApply>(transform)...);