1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
template <typename VECTOR_TYPE = char,int VECTOR_SIZE = 256>
class vector{
private:
int SIZE;
VECTOR_TYPE ARRAY[VECTOR_SIZE];
public:
vector():SIZE(VECTOR_SIZE){
}
VECTOR_TYPE& operator[](int nIndex){
assert(nIndex >= 0 && nIndex < SIZE);
return ARRAY[nIndex];
}
void DIn(VECTOR_TYPE data,int nIndex){
assert(nIndex >= 0 && nIndex < SIZE);
ARRAY[nIndex] = data;
}
int sizeof_vector(){
return SIZE;
}
};
template <typename VECTOR_TYPE,int VECTOR_SIZE1,int VECTOR_SIZE2>
void vector_memcpy(
vector <VECTOR_TYPE,VECTOR_SIZE1> *target,int tIdx,
vector <VECTOR_TYPE,VECTOR_SIZE2> source,int sIdx,
int Length){
int i;
for(i=0;i<Length;i++)
target->DIn(source[sIdx+i],tIdx+i);
}
int main(){
vector <int,16> AV;
vector <int,32> BV;
int i;
for(i=0;i<16;i++)
AV[i] = i*15;
vector_memcpy(&BV,0,AV,0,16);
vector_memcpy(&BV,16,BV,0,16);
for(i=0;i<16;i++)
printf("%2d: %3d %3d %3d\n",i,AV[i],BV[i],BV[i+16]);
return 0;
}
|