Re: is there any reason UFCS can't be used with 'new'?
On Sunday, 28 September 2014 at 22:17:03 UTC, Meta wrote: I'm not sure. Maybe it's on the same level as the Lambda Abstraction (14.5), but you'll probably have to do some testing to figure it out exactly. precedence levels seem to be defined in `src/parse.h` (the `PREC` enum) and assigned to operators in `src/parse.c` (`initPrecedence()`).
is there any reason UFCS can't be used with 'new'?
i want to chain 'new' with method calls on the created object. i found this on the internet: window.mainWidget = (new Button()).text(Hello worldd).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget = Button.new().text(Hello worldd).textColor(0xFF); well, it's not *exactly* UFCS but you get what i mean.
Re: is there any reason UFCS can't be used with 'new'?
thanks! but i'm still interested *why* you can't have this with 'new'. if there's no good reason i will file a bug report. On Sunday, 28 September 2014 at 19:19:56 UTC, Foo wrote: mixin template New(T) if (is(T == class)) { static T New(Args...)(Args args) { return new T(args); } } class Bar { string txt; this() { txt = Foo; } this(string t) { txt = t; } mixin New!Bar; } void main() { import std.stdio; writeln(Bar.New().txt); writeln(Bar.New(Bar).txt); }
Re: is there any reason UFCS can't be used with 'new'?
On Sunday, 28 September 2014 at 19:41:29 UTC, Idan Arye wrote: Because `new` is not a function - it's an operator. do you think the function call syntax has any chance to be implemented? is it just me who needs it?
Re: is there any reason UFCS can't be used with 'new'?
On Sunday, 28 September 2014 at 19:19:56 UTC, Foo wrote: mixin template New(T) if (is(T == class)) { static T New(Args...)(Args args) { return new T(args); } } fwiw here's what i wrote: template New(T) if (is(T == class)) { T New(Args...) (Args args) { return new T(args); } } ... New!Bar(hi).txt.writeln; not as neat as your version but still improves on the ugly (new Class()).method syntax and doesn't need to be mixed into the class definition.
Re: is there any reason UFCS can't be used with 'new'?
On Sunday, 28 September 2014 at 20:30:42 UTC, Meta wrote: class Button { typeof(this) text(string t) { return this; } typeof(this) textColour(int c) { return this; } } void main() { auto b = new Button() .text(Hello, world!) .textColour(0xFF00); } thanks! where should i put it in this table: http://wiki.dlang.org/Operator_precedence ?
Is there a function that reads the entire contents of a std.stdio.File?
all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is there?). i need a function that takes a std.stdio.File and returns a string or byte array.
Re: Is there a function that reads the entire contents of a std.stdio.File?
On Tuesday, 16 September 2014 at 14:43:10 UTC, Marc Schütz wrote: You could try `std.mmfile.MmFile`, it has a constructor that takes a `File`, but only on Linux: http://dlang.org/phobos/std_mmfile.html https://github.com/D-Programming-Language/phobos/blob/master/std/mmfile.d#L77-L79 does it work with pipes/sockets? it seems to call fstat() to get the size of the contents. but anyway this is quite useful, thanks.
Re: Is there a function that reads the entire contents of a std.stdio.File?
On Tuesday, 16 September 2014 at 14:49:08 UTC, Daniel Kozak via Digitalmars-d-learn wrote: You can use rawRead: http://dlang.org/phobos/std_stdio.html#.File.rawRead for that i need to know the size of the contents. is there a function that does that for me? i'm looking for something like someFile.readAll(). and it shouldn't matter whether the File instance represents a regular file or a pipe/stream.
Re: Is there a function that reads the entire contents of a std.stdio.File?
On Tuesday, 16 September 2014 at 15:03:05 UTC, Jay wrote: and it shouldn't matter whether the File instance represents a regular file or a pipe/stream. i meant pipe/socket.
Re: Is there a function that reads the entire contents of a std.stdio.File?
On Tuesday, 16 September 2014 at 16:54:17 UTC, Ali Çehreli wrote: On 09/16/2014 07:37 AM, Jay wrote: all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is there?). i need a function that takes a std.stdio.File and returns a string or byte array. std.file.read (and readText): http://dlang.org/phobos/std_file.html#.read Ali wait, std.file.read doesn't accept a File instance. i've got a File instance generated by another function and now i need to read the entire contents of whatever it represents (a regular file/pipe/etc).
Re: Is there a function that reads the entire contents of a std.stdio.File?
On Tuesday, 16 September 2014 at 18:42:42 UTC, Justin Whear wrote: The short answer is no. I usually use something like this: // Lazy auto stream = stdin.byChunk(4096).joiner(); You can make it eager by tacking a `.array` on the end. Functions used are from std.stdio, std.algorithm, std.array. thanks. that's exactly what i need.