Messing with betterC and string type.
Adam D. Ruppe
destructionator at gmail.com
Thu Sep 6 16:50:01 UTC 2018
On Thursday, 6 September 2018 at 16:24:12 UTC, SrMordred wrote:
> alias string = String;
For the rest of this module, any time you write `string`, the
compiler sees `String`. But inside the compiler, it still thinks
of its own string, hence the confusing looking error messages.
> struct String{
> this(string x){}
> }
And this is going to be seen as
this(String x) {}
instead of what you wanted. Try
this(object.string x) {}
which MIGHT work, or
this(immutable(char)[] x) {}
which will work - immutable(char)[] is what object.string
actually is (and the compiler will often use that -
immutable(char)[], the proper name - and string, the
user-friendly name, totally interchangably).
> My question is, i´m breaking something else, or this could be a
> valid approach?
It is valid as long as you keep the names straight. Though it
won't be as cool as you think because D doesn't do implicit
construction, so
void foo(string s) {}
foo("this");
won't compile, since it won't make a String out of that
immutable(char)[] literal without an explicit initialization of
some sort.
You could, of course, just do a wrapper function or whatever, but
really I think you are better off just trying to work with
immutable(char)[]...
More information about the Digitalmars-d
mailing list