You don't need a rooted iterator here since obj is available. Just keep itBegin and subtract it - itBegin. That should be faster as it uses pointers instead of the more complex adaptor iterator