is a better way to implement this code ?
int getBlockVector(vector<unsigned char>& vect, const int pos, const int length)
{
int destinyInt = 0;
switch (length) {
case 1 : destinyInt = (0x00 << 24) | (0x00 << 16) | (0x00 << 8) | vecct.at(pos); break;
case 2 : destinyInt = (0x00 << 24) | (0x00 << 16) | (vect.at(pos + 1) << 8) | vect.at(pos); break;
case 3 : destinyInt = (0x00 << 24) | (vect.at(pos + 2) << 16) | (vect.at(pos + 1) << 8) | vect.at(pos); break;
case 4 : destinyInt = (vect.at(pos + 3) << 24) | (vect.at(pos + 2) << 16) | (vect.at(pos + 1) << 8) | vect.at(pos); break;
default : destinyInt = -1;
return destinyInt;}
considering the ugly default value. How implement this function with iterators and template for vector, deque, queue, etc.
Note: the bounds are checked before and static_cast is not a desirable option.