I want to concatenate two structs. The problem is that I cannot convert that struct to a std::span, because span's constructor doesn't support void*. I'm using the same concat function to concatenate std::vector<uint8_t> as well, so any changes made to that function, shouldn't affect it. If it's possible to convert the struct to vector<uint8_t>, I will be able to change std::span<uint8_t> to vector of the same. How can I do that?
address_t address{};
memcpy(address.country, country, sizeof country);
memcpy(address.city, city, sizeof city);
memcpy(address.state, state, sizeof state);
address.zip_code = zip_code;
...
const auto& a = reinterpret_cast<void*>(&address);
auto c = utils::concat(a, b);
Snippet
__declspec(align(16))
typedef struct
{
std::wchar_t country[30];
std::wchar_t city[50];
std::wchar_t state[50];
std::uint32_t zip_code;
} address_t;
namespace utils
{
inline std::vector<std::uint8_t> concat(const std::span<std::uint8_t>& a)
{
return std::vector<std::uint8_t>(a.data(), a.data() + a.size());
}
template <typename... Args>
std::vector<std::uint8_t> concat(const std::span<std::uint8_t>& a, Args&... args)
{
auto vec = std::vector<std::uint8_t>(a.data(), a.data() + a.size());
(vec.insert(vec.end(), args.begin(), args.end()), ...);
return vec;
}
}