Ascii string literal.

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 6 13:29:35 PDT 2016


On Friday, 6 May 2016 at 20:01:27 UTC, Alexandru Ermicioi wrote:
> Is it possible somehow to convert implicitly a string literal

Not implicitly (well, unless you just use string, ascii is a 
strict subset of utf-8 anyway), but you could do it explicitly 
easily.

immutable(ubyte)[] ascii(string s) { return cast(typeof(return)) 
s; }


Then use it like

ascii("your string")

or make it a template and use ascii!"your string" or "your 
string".ascii whatever.

You could (and imo should!) also make a struct to hold the new 
type.


More information about the Digitalmars-d-learn mailing list