Where are the strings in std.string?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Oct 27 10:07:18 PDT 2012
On Sat, Oct 27, 2012 at 06:53:56PM +0200, TheManWithNoName wrote:
> I don't mean to be splitting hairs here, well maybe I do, but
>
> D clearly makes the string type to be immutable(char)[]. That's
> fine, but the std.string is all about char[] or mutable character
> arrays.
Huh?
I think you're confusing const(char)[] for char[]. In D, both T[] and
immutable(T)[] for any type T can be implicitly converted to const(T)[].
The reason many of the functions in std.string take const(T)[] is
because they work with *both* string and char[].
There is also a bunch of template functions that take C[] for any
character type C. This means it can take char[], const(char)[], string,
wchar[], wstring, dchar[], dstring, etc.. These are all generic
functions. Most of these functions don't require mutable strings at all.
> So now, whenever I see a reference to the string, I have to ask
> myself: do they mean the formal definition of string,
> immutable(char)[], or the colloquial version, char[].
[...]
There is no colloquial version of string, a string in D is always
immutable(char)[]. char[] is called a character array.
T
--
It is widely believed that reinventing the wheel is a waste of time; but I disagree: without wheel reinventers, we would be still be stuck with wooden horse-cart wheels.
More information about the Digitalmars-d-learn
mailing list