C++ Logo

std-proposals

Advanced search

Re: [std-proposals] basic_string_view::const_reverse_iterator

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 18 Jan 2023 12:03:13 -0500
On Wed, Jan 18, 2023 at 11:54 AM Robert Allan Schwartz via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> Hello,
>
> Today I am making my first posts to this group. Please forgive me if I make mistakes. Thank you.
>
> Here is the context:
>
> Header <string_view>:
>
> template<class charT, class traits = char_traits>
> class basic_string_view {
> public:
> // types
> using traits_type = traits;
> using value_type = charT;
> using pointer = value_type*;
> using const_pointer = const value_type*;
> using reference = value_type&;
> using const_reference = const value_type&;
> using const_iterator = implementation-defined ; // see 24.4.2.2
> using iterator = const_iterator;228
> using const_reverse_iterator = reverse_iterator<const_iterator>;
> using reverse_iterator = const_reverse_iterator;
>
> I understand that the alias declaration for const_reverse_iterator uses the only declaration of reverse_iterator that is in scope at that moment, which is std::reverse_iterator, but then reverse_iterator is defined again on the next line, which creates an ordering dependency.
>
> Wouldn't it be safer and clearer to say:
>
> using const_reverse_iterator = std::reverse_iterator<const_iterator>;
>
> This would eliminate the ordering issue.

There is no ordering issue. Because `basic_string_view` exists inside
the `std` namespace, `reverse_iterator` will refer to the namespace
declaration. There is nothing that needs to be changed.

Received on 2023-01-18 17:03:34