I get an array from the C API, and I would like to copy it to std :: array for later use in my C ++ code. So what is the right way to do this?
I 2 uses for this, one of them:
struct Foo f;
c_api_function(&f);
std::array<uint8_t, 32> a;
memcpy((void*)a.data(), f.kasme, a.size());
And this one
class MyClass {
std::array<uint8_t, 32> kasme;
int type;
public:
MyClass(int type_, uint8_t *kasme_) : type(type_)
{
memcpy((void*)kasme.data(), kasme_, kasme.size());
}
...
}
...
MyClass k(kAlg1Type, f.kasme);
But that seems pretty awkward. Is there an idiomatic way to do this that is apparently not related to memcpy? For MyClass, maybe I'm better off with a constructor that takes a std :: array that moves to a member, but I also can't figure out how to do this.?
source
share