Reference Array - add a sub topic for handling arrays

kowalski:
There are more tricks to be played in C++ as operators may be defined for the struct/class. With a template class you can also handle different array sizes and avoid using the heap (malloc/free, new/delete).
Cheers!

GCC also supports compound literals. Not something which is standard.

Assign new array to old array using kowalski's struct & compund literal:

//Initialisation, this is standard use.
array_t matrix = {{ 'a','b','c','d','e','f','g','\0' }};

//Assignment using compound literal
matrix = ( array_t  ){{ 'h','i','j','k','l','m','n','\0' }};

Using a template version of memcpy ( passing size in like standard memcpy, 3 params ):

template< typename T >
  T *arrcpy( T *dest, const T *source, int size ){
    while( --size >= 0x00 ){ dest[ size ] = source[ size ]; }
    return dest;
  }

Using a template version of memcpy specifically for arrays ( no third parameter to pass size ):

template< typename T, size_t N >
  T *arrcpy( T (&dest)[N], const T (&source)[N] ){
    int size = N;
    while( --size >= 0 ){ dest[ size ] = source[ size ]; }
    return dest;
  }