dimanche 26 avril 2020

How a C++11 constexpr constructor fully initialize a C-style array from a pointer?

In c++11, I want to have a struct like the following:

template<unsigned n> struct bytes_block {
    char data[n];
    constexpr bytes_block(char const *s):data(....) {}
};

It can be safely assumed that the constructor parameter 's' points to a region of memory where at least n consecutive characters can be copied from starting at 's' from without invoking any UB in the constructor.

I do not know how to fill in the ... above, however.

Can a constexpr implementation for the bytes_block constructor be made which would be C++11 compliant? Any number of additional constexpr functions may be created to be used as helpers, as long as of course they consist of only a single return statement.

Aucun commentaire:

Enregistrer un commentaire