Is there a reason why make_reverse_iterator(make_reverse_iterator(it)) results in a different type?

  c++, c++-standard-library

I would think that:

static_assert(is_same_v<
    decltype(make_reverse_iterator(make_reverse_iterator(it)))
  , decltype(it)>);

would compile, but it doesn’t. Is there some reason why this is? I can see this as potentially resulting in larger generated code when writing templates.

This isn’t that difficult to implement:

template <typename T>
T make_reverse_iterator(reverse_iterator<T> it) {
  return it.base();
}

and would result in a smaller binary if double or more reversals are done when calling a template function, especially if that function were to say call itself recursively using a reverse_iterator of what it was called with without complicating the code with other specializations.

Source: Windows Questions C++

LEAVE A COMMENT