Q:

Subtraction of iterators and integers

I'm researching the basic sorting algorithms and I was looking about Shell Sort here:
https://github.com/nicolausYes/iterator-template-sort-library/blob/master/src/ShellSort.h
Here is the relevant code:
template< class RandomAccessIterator, class Compare >
static void sort( RandomAccessIterator first, RandomAccessIterator last, Compare comp )
{
    auto size = last - first;
    auto h = 1;
    while( h < size / 3 ) h = 3 * h + 1;

    while( h >= 1 )
    {
        for( auto i = first + h; i != last; i++ )
        {
            for( auto j = i; (j - first) >= h && comp(*j, *(j-h)); j -= h )
                std::swap( *j, *(j-h) );
        }

        h /= 3;
    }
}

When he declares size, is it supposed to be an integral value or another iterator? Because he's dividing it by numbers later like this : "size / 3"
But when he calls std::swap(*j, *(j - h)); he's swapping the insides of 2 iterators, so there j - h returns an iterator. If "size" is an iterator then, what does / do to it? I mean if it just splits the internal pointer by 3, that would make no sense.

A:

Subtracting one iterator from another should yield an integer. The STL's random access iterators yield a value of type ptrdiff_t when subtracted. It's good practice to use this type when implementing iterators in general. However, in practice, if you want to use, say, int, that's usually fine too.
Subtracting an integer from an iterator yields another iterator.

