C++ Logo


Advanced search

Re: std::span

From: Lyberta <lyberta_at_[hidden]>
Date: Mon, 20 Apr 2020 12:32:46 +0300
Ville Voutilainen:> That "unsafe code" will compile anyway, you've just made it
> inconvenient to write - we need to use a compare() function
> as opposed to just using operator==.
Unsafe code must be inconvenient to write. For that reason reinterpret_cast is named that way. The fact that
std::set<std::string_view> and std::map<std::string_view, T> compile is a bug.

> Also, by that definition,
> references and pointers are similarly unsafe
Sure, have you ever seen std::set<char*> or std::map<char*, T>? At least it is common knowledge that raw pointers are unsafe and
shouldn't be used in most code.

> A major use case for span and string_view is parsing - get a sub-range
> to something, compare it like it's a whole
> range.
Sure, if you want deep comparison, use explicit code. For pointers you'd do *i == *j. Dereference is explicit.

Received on 2020-04-20 04:35:46