I'd like a way to take an arbitrary-size array of bytes and return a hex string. Specifically for logging packets sent over the net, but I use the equivalent function that takes a std::vector a lot. Something like this, probably a template?
std::string hex_str(const std::array<uint8_t,???> array);
I've searched but the solutions all say "treat it as a C-style array" and I am specifically asking whether there's a way not to do that. I assume the reason this isn't in every single C++ FAQ is that it's impossible and if so can someone outline why?
I already have these overloads and the second one can be used for std::array by decaying into a C-style array, so please don't tell me how to do that.
std::string hex_str(const std::vector<uint8_t> &data);
std::string hex_str(const uint8_t *data, const size_t size);
(edit: vector is a reference in my code)
template <std::size_t N> std::string hex_str(const std::array<uint8_t, N> array);std::arrayknown at compile time? If not, then no, the sized have to be known at compile time. What if instead you took iterators? That way someone can use whatever container they'd like.std::vectorandstd::array? Or even better, an iterator range? The whole point of standard containers having a consistent interface is for cases like this, so you can write a single algorithm that handles multiple container types equally