Here is a different (more verbose) way:
uint16_t myarray[] = { 0, 1, 2, 3, 4, 5, 6, ..., n };
constexpr auto arr_size = sizeof(myarray) / sizeof(myarray[0]);
constexpr auto copy_start = std::min< size_t >(3, arr_size);
constexpr auto copy_count = 19;
constexpr auto copy_end = std::min< size_t >(copy_start + copy_count, arr_size);
vector< uint16_t > myvect(std::next(myarray, copy_start), std::next(myarray, copy_end));
Instead of UINT16
you can use uint16_t
type from C++11 onwards: Fixed width integers (if your compiler supports it)
If your values are available at compile time, then you can use compile time constants(constexpr
) to calculate the helper variables. Otherwise const
should be used.
Standard algorithms can be used also on arrays so providing an offset to std::next
can be used to get the n-th element of an array.