The problem that took him 5 years to fix in C++, I solved in a minute with D

IGotD- nise at nise.com
Thu Mar 10 21:00:56 UTC 2022


On Thursday, 10 March 2022 at 20:44:11 UTC, Steven Schveighoffer 
wrote:
>
> It's because std::string_view doesn't manage its memory. If 
> std::string worked at compile time, he would have just done 
> that.
>
> std::string_view is the equivalent of D's string, it has a 
> pointer and length. std::string is the equivalent of the 
> nefarious GC array management mechanism that has no type or 
> name, but works great at both runtime and compile time.
>
> -Steve

In practice you can make std::string work similar to the strings 
in D, it's just a matter of choice. I think std::string was 
previously reference counted but they went away from that. 
Another reason is that in std::string, NUL is currently always 
added at the end. The c_str() method is a bit guilty of that even 
if it is possible to make the conversion lazy. It's just a 
cascade of bad design decisions that made C++ end up with 
string_view.

I like the strings in D which are miles better and we also see 
how this design decision was the right one (which several other 
languages also did).


More information about the Digitalmars-d mailing list