digitalmars.D - auto decoding rant
- Jonathan Shamir (33/33) Jun 15 2017 I see this is a recurring rant (I apologize if this is a
- Seb (5/7) Jun 15 2017 Have a look at:
- Jonathan Shamir (2/10) Jun 15 2017 Perfect, thanks!
- Jonathan M Davis via Digitalmars-d (6/39) Jun 15 2017 Yes, it should be the other way around, but changing it at this point
I see this is a recurring rant (I apologize if this is a repeating topic, I'm new to the forums). Here's an example of something that should be simple in D but isn't: enum string PATTERN = "abcd"; immutable char[10] repeatingPattern = PATTERN.cycle().takeExactly(10).array(); The fact that front(string) returns a dchar makes some really simple (and common) use-cases practically impossible. Also note I can't cast to char[] in compile time? What's the reason for that? I would recommend adding something like this to phobos (and in all fairness, it should have been the other way around): auto noDecode(T)(T[] str) if (isNarrowString!(T[])) { static struct NoDecode { private T[] str; property ref T front() { assert (!this.empty); return str[0]; } property bool empty() { return (str.empty); } void popFront() { if (!this.empty) { str = str[1 .. $]; } } NoDecode save() { return this; } } return NoDecode(str); }
Jun 15 2017
On Thursday, 15 June 2017 at 15:47:54 UTC, Jonathan Shamir wrote:Also note I can't cast to char[] in compile time? What's the reason for that?Have a look at: https://dlang.org/phobos/std_utf.html#byCodeUnit https://dlang.org/phobos/std_utf.html#byChar https://dlang.org/phobos/std_string.html#.representation
Jun 15 2017
On Thursday, 15 June 2017 at 15:50:42 UTC, Seb wrote:On Thursday, 15 June 2017 at 15:47:54 UTC, Jonathan Shamir wrote:Perfect, thanks!Also note I can't cast to char[] in compile time? What's the reason for that?Have a look at: https://dlang.org/phobos/std_utf.html#byCodeUnit https://dlang.org/phobos/std_utf.html#byChar https://dlang.org/phobos/std_string.html#.representation
Jun 15 2017
On Thursday, June 15, 2017 15:47:54 Jonathan Shamir via Digitalmars-d wrote:I see this is a recurring rant (I apologize if this is a repeating topic, I'm new to the forums). Here's an example of something that should be simple in D but isn't: enum string PATTERN = "abcd"; immutable char[10] repeatingPattern = PATTERN.cycle().takeExactly(10).array(); The fact that front(string) returns a dchar makes some really simple (and common) use-cases practically impossible. Also note I can't cast to char[] in compile time? What's the reason for that? I would recommend adding something like this to phobos (and in all fairness, it should have been the other way around):Yes, it should be the other way around, but changing it at this point without massive code breakage is very difficult if not impossible.auto noDecode(T)(T[] str) if (isNarrowString!(T[])) { static struct NoDecode { private T[] str; property ref T front() { assert (!this.empty); return str[0]; } property bool empty() { return (str.empty); } void popFront() { if (!this.empty) { str = str[1 .. $]; } } NoDecode save() { return this; } } return NoDecode(str); }Already there: http://dlang.org/phobos/std_utf.html#byCodeUnit - Jonathan M Davis
Jun 15 2017