C++ Logo

std-proposals

Advanced search

Re: [std-proposals] basic_string_view::const_reverse_iterator

From: Robert Allan Schwartz <notbob_at_[hidden]>
Date: Wed, 18 Jan 2023 17:08:33 +0000
Hi Jason,

You're correct, there is nothing that *needs* to be changed.

I was only proposing an improvement for purposes of clarity, and to prevent a potential error if a future edition of the Standard mistakenly reverses the order of those two lines.

Thanks,

Robert

> On Jan 18, 2023, at 12:03 PM, Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-01-18 17:08:37