This commit is contained in:
Timur A. Fatkhullin
2026-07-22 00:16:31 +03:00
parent 7360e7eede
commit 0130420f90

View File

@@ -54,9 +54,45 @@ struct snplib_netproto_stopseq_t {
}
}
template <std::ranges::range OR, std::ranges::range IR>
OR fromBytes(IR&& bytes)
template <std::ranges::range OR, snplib_input_char_range_c IR>
std::expected<OR, std::error_code> fromBytes(IR&& bytes)
{
auto found = std::ranges::search(std::forward<IR>(bytes), NETPROTO_STOP_SEQ);
if (found.empty()) {
return std::unexpected(std::errc::invalid_argument);
}
if constexpr (std::ranges::contiguous_range<IR>) {
if constexpr (std::ranges::view<OR>) {
return OR(bytes.begin(), found.begin()); // return without stop-sequence!!!
} else if constexpr (snplib_output_char_range_c<OR>) {
OR res;
std::ranges::copy(
std::forward<IR>(bytes) | std::views::take(std::distance(bytes.begin(), found.begin())),
std::back_inserter(res));
return res;
} else {
static_assert(false, "Unsupported output byte sequence type!");
}
} else {
}
if constexpr (snplib_output_char_range_c<OR>) {
OR res;
std::ranges::copy(std::forward<IR>(bytes) | std::views::take(std::distance(bytes.begin(), found.begin())),
std::back_inserter(res)); // return without stop-sequence!!!
return res;
} else if constexpr (snplib_char_view_c<OR>) {
if constexpr (std::ranges::contiguous_range<IR>) {
return OR(bytes.begin(), found.begin()); // return without stop-sequence!!!
} else {
static_assert(false, "Unsupported output byte sequence type!");
}
} else {
static_assert(false, "Unsupported output byte sequence type!");
}
}
};