#ifndef __AMSCPPNARRAY_IMPLSUBARRAY_HPP__
#define __AMSCPPNARRAY_IMPLSUBARRAY_HPP__

namespace ams
{
namespace narray
{

    template<typename T> narray<T> narray<T>::subarray(const narray_size_t ind1, const narray_size_t ind2) const
    {
        int res;
        narray<T> ret;
        T defval = T();
        narray_size_t I,J;

        int nl = ind2-ind1;

        if(nl<=0)
        {
            ret.resize(0);
            return ret;
        }

        ret.resize(nl);
        for(I=0;I<nl;I++)
        {
            J = I + ind1;
            if(J<0 || J>=this->length)
            {
                ret.data[I] = defval;
            }
            else
            {
                ret.data[I] = this->data[J];
            }
        }
        
        return ret;
    }

};
};

#endif