C++ Logo


Advanced search

Re: why does std::basic_string should accept an std::basic_string_view with the same charT and Traits

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 14 Sep 2020 11:23:01 -0700
On Monday, 14 September 2020 06:56:51 PDT Jason McKesson via Std-Proposals
> But yes, I do agree that saying "is like comparing unsigned with float
> point or bool with int" is wrong. They are *conceptually* storing the
> same data; they are only different types because of the need to do
> special static things with their allocators. The allocator type being
> part of the string's type is a wart of the language, not a fundamental
> part of what it means to be a "string". So long as the character and
> traits types are the same, I think it is perfectly valid to compare
> them.

The way it is defined to be, it actually is. The allocator defines how to
refer to the data itself, including what a pointer or reference to the data
itself is. String comparison calls the character traits compare() function
with the pointer to the data on both strings and the length, both things
requiring the allocator to define.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2020-09-14 13:23:09