Currently I'm struggling with something like this:
class Command final {
const std::vector<uint8_t> cmd;
public:
constexpr Command(const std::initializer_list<uint8_t> cmd_)
:cmd(cmd_)
{}
void copyToWithSlightModifications(uint8_t* buf, size_t len) { /*...*/ }
std::string getSomeInformation() { /*...*/ }
}
const Command cmd1({ 0x01, 0x02, 0x03 });
const Command cmd2({ 0x01, 0x02, 0x03, 0x04 });
// lots more of these
Of course, std::vector
is not something that works here, but it's here as it expresses my intent best. I tried std::array
and a few other ideas, but also have failed.
Background: this is for embedded development, so I'm tight on resources and consting things tends to put them to flash where memory is cheap. Doing it as a real vector will put this into scarce RAM memory. This is on gcc version 5.2.0.
TL;DR: I need to have a variable length container that I can put as a field on a const object with and initialize it in constexpr context. Any idea what that might look like? Doesn't have to be anything fancy, if it's a uint8_t*
and a size_t
with it's size, that will work too.