Re: Is this a bug?

2018-10-15 Thread Ali Çehreli via Digitalmars-d-learn
On 10/15/2018 01:36 PM, Márcio Martins wrote: > Considering that the declaration is legal, and that the template > parameter deduction works when Args.length == 0, but stops working when > Args.length > 0. For deduction to work, there must be function arguments. So, just add Args to the functio

Re: Reading binary streams with decoding to Unicode

2018-10-15 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 15 October 2018 at 21:48:05 UTC, Vinay Sajip wrote: On Monday, 15 October 2018 at 19:56:22 UTC, Nicholas Wilson wrote: import std.file : readText; import std.uni : byCodePoint, byGrapheme; // or import std.utf : byCodeUnit, byChar /*utf8*/, byWchar /*utf16*/, byDchar /*utf32*/, byUT

Re: Reading binary streams with decoding to Unicode

2018-10-15 Thread Vinay Sajip via Digitalmars-d-learn
On Monday, 15 October 2018 at 19:56:22 UTC, Nicholas Wilson wrote: import std.file : readText; import std.uni : byCodePoint, byGrapheme; // or import std.utf : byCodeUnit, byChar /*utf8*/, byWchar /*utf16*/, byDchar /*utf32*/, byUTF /*utf8(?)*/; string a = readText("foo"); foreach(cp; a.byCo

Re: Is this a bug?

2018-10-15 Thread Márcio Martins via Digitalmars-d-learn
On Monday, 15 October 2018 at 16:46:34 UTC, Steven Schveighoffer wrote: On 10/15/18 12:40 PM, Márcio Martins wrote: import std.stdio; void incx(T, Args...)(ref T t) {     ++t.x; } static struct Test(T) {     T x; } void main() {     Test!uint t;     t.incx();   // works     t.inc

Re: Reading binary streams with decoding to Unicode

2018-10-15 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 15 October 2018 at 18:57:19 UTC, Vinay Sajip wrote: On Monday, 15 October 2018 at 17:55:34 UTC, Dukc wrote: This is done automatically for character arrays, which includes strings. wchar arrays wil iterate by UTF-16, and dchar arrays by UTF-32. If you have a byte/ubyte array you kno

Re: Reading binary streams with decoding to Unicode

2018-10-15 Thread Vinay Sajip via Digitalmars-d-learn
On Monday, 15 October 2018 at 17:55:34 UTC, Dukc wrote: This is done automatically for character arrays, which includes strings. wchar arrays wil iterate by UTF-16, and dchar arrays by UTF-32. If you have a byte/ubyte array you know to be unicode-encoded, convert it to char[] to iterate by code

Re: Reading binary streams with decoding to Unicode

2018-10-15 Thread Dukc via Digitalmars-d-learn
On Monday, 15 October 2018 at 10:49:49 UTC, Vinay Sajip wrote: Is there a standardised way of reading over buffered binary streams (at least strings, files, and sockets) where you can layer a decoder on top, so you get a character stream you can read one Unicode char at a time? Initially UTF-8,

Re: Is this a bug?

2018-10-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/15/18 12:46 PM, Steven Schveighoffer wrote: Did you mean incx!(T, 1, 2, 3)(t) ? Sorry, incx!(Test!uint, 1, 2, 3)(t) -Steve

Re: Is this a bug?

2018-10-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/15/18 12:40 PM, Márcio Martins wrote: import std.stdio; void incx(T, Args...)(ref T t) {     ++t.x; } static struct Test(T) {     T x; } void main() {     Test!uint t;     t.incx();   // works     t.incx!();  // works     incx(t);    // works     t.incx!(1,

Is this a bug?

2018-10-15 Thread Márcio Martins via Digitalmars-d-learn
import std.stdio; void incx(T, Args...)(ref T t) { ++t.x; } static struct Test(T) { T x; } void main() { Test!uint t; t.incx(); // works t.incx!(); // works incx(t);// works t.incx!(1, 2, 3); // what? incx(t, 1, 2, 3); // what?

Re: How can I induce implicit type convesion with alias this on calling template function?

2018-10-15 Thread Sobaya via Digitalmars-d-learn
On Monday, 15 October 2018 at 06:16:34 UTC, Alex wrote: On Monday, 15 October 2018 at 04:51:39 UTC, Sobaya wrote: [...] Removing constraint, but retaining specialization should be enough, no? Then, func is still a template, requiring the argument to be convertible to an int. When S is passed

Re: custom sorting of lists ?

2018-10-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/13/18 9:31 PM, Jonathan M Davis wrote: On Saturday, October 13, 2018 6:52:05 PM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: You can't quick-sort a list. You can merge sort it, and it's O(nlgn). I'll work on getting a sort routine into Phobos for it, but I don't know what the a

Reading binary streams with decoding to Unicode

2018-10-15 Thread Vinay Sajip via Digitalmars-d-learn
Is there a standardised way of reading over buffered binary streams (at least strings, files, and sockets) where you can layer a decoder on top, so you get a character stream you can read one Unicode char at a time? Initially UTF-8, but later also other encodings. I see that std.stream was depr

Re: Noob question about structs allocation

2018-10-15 Thread Mike Parker via Digitalmars-d-learn
On Monday, 15 October 2018 at 04:14:24 UTC, IM wrote: What is the effect of calling destroy? - calling the destructor? - deallocating the memory? - both? It calls the destructor. The GC will deallocate the object's memory later. However, you need to be careful about how you use GC-allocated

Re: Noob question about structs allocation

2018-10-15 Thread Laurent Tréguier via Digitalmars-d-learn
On Monday, 15 October 2018 at 04:14:24 UTC, IM wrote: What is the effect of calling destroy? - calling the destructor? - deallocating the memory? - both? IIRC, it only calls the destructor, the GC will decide when to deallocate the memory.