Re: How to reliably detect an alias sequence?

2020-12-27 Thread Max Samukha via Digitalmars-d-learn
On Sunday, 27 December 2020 at 18:25:10 UTC, sighoya wrote: This should work: ``` static assert(is(int == AliasSeq!int)); Drepl: static assert: `is(int == (int))` is false ``` That will only work for type tuples. We need a general solution that would work for any alias tuple. The most

Re: Tool to measure the time a function takes to execute?

2020-12-27 Thread Kirill via Digitalmars-d-learn
On Monday, 28 December 2020 at 07:00:59 UTC, Ali Çehreli wrote: On 12/27/20 10:24 PM, Kirill wrote: Hello, is there a tool to measure the execution time of a function in D? Can the GC do it? StopWatch and benchmark(): https://dlang.org/phobos/std_datetime.html Ali Thanks Ali! That's

Re: Tool to measure the time a function takes to execute?

2020-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/20 10:24 PM, Kirill wrote: Hello, is there a tool to measure the execution time of a function in D? Can the GC do it? StopWatch and benchmark(): https://dlang.org/phobos/std_datetime.html Ali

Tool to measure the time a function takes to execute?

2020-12-27 Thread Kirill via Digitalmars-d-learn
Hello, is there a tool to measure the execution time of a function in D? Can the GC do it?

Re: Reading files using delimiters/terminators

2020-12-27 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 27 December 2020 at 23:18:37 UTC, Rekel wrote: Update; Any clue why there's both "std.file" and "std.io.File"? I was mostly unaware of the former. The very first paragraph at the top of the `std.file` documentation explains it: "Functions in this module handle files as a unit,

Custom type / Typle type formatted reader

2020-12-27 Thread Rekel via Digitalmars-d-learn
It's more of a multi-part question, I've been trying to read tuples using 'slurp', though later realised one of the types was an enum, I'm guessing that's what was the problem, which lead me down a whole rabbit hole. - Can I directly read tuples using slurp? It doesnt seem to like

Re: Reading files using delimiters/terminators

2020-12-27 Thread oddp via Digitalmars-d-learn
On 28.12.20 00:12, Rekel via Digitalmars-d-learn wrote: is there a reason to use either 'splitter' or 'split'? split gives you a newly allocated array with the results, splitter is lazy equivalent and doesn't allocate. Feel free using either, doesn't matter much with these small puzzle

Re: Reading files using delimiters/terminators

2020-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/20 3:12 PM, Rekel wrote: > is there a reason to use > either 'splitter' or 'split'? I'm not sure I see why the difference > would matter in the end. splitter() is a lazy range algorithm. split() is a range algorithm as well but it is eager; it will put the results in an array that it

Re: Reading files using delimiters/terminators

2020-12-27 Thread Rekel via Digitalmars-d-learn
On Sunday, 27 December 2020 at 23:12:46 UTC, Rekel wrote: Sidetangent, don't mean to bash the learning tour, as it's been really useful for getting started, but I'm surprised stuff like tuples and files arent mentioned there. Update; Any clue why there's both "std.file" and "std.io.File"? I

Re: Reading files using delimiters/terminators

2020-12-27 Thread Rekel via Digitalmars-d-learn
On Sunday, 27 December 2020 at 13:27:49 UTC, oddp wrote: foreach (group; readText("input").splitter("\n\n")) { ... } Also, on other days, when the input is more uniform, there's always https://dlang.org/library/std/file/slurp.html which makes reading it in even easier, e.g. day02: alias

Re: How to resize an image ? 樂

2020-12-27 Thread JN via Digitalmars-d-learn
On Friday, 25 December 2020 at 20:59:03 UTC, vnr wrote: Hello  For a small "script" that generates printable files, I would need to change the size of an image (which is loaded into memory as an array of bytes) to shrink it to scale if it exceeds the A4 page size. To load the images into

Re: How to resize an image ? 樂

2020-12-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 December 2020 at 18:48:18 UTC, vnr wrote: The one given at the beginning by Adam D. Ruppe was fine with me, fyi i think I am going to move that resize code from image.d to a more independent imageresize.d or something. Same repo. Obviously won't affect you if you already using

Re: How to resize an image ? 樂

2020-12-27 Thread vnr via Digitalmars-d-learn
On Sunday, 27 December 2020 at 16:49:49 UTC, Guillaume Piolat wrote: On Friday, 25 December 2020 at 20:59:03 UTC, vnr wrote: Hello  For a small "script" that generates printable files, I would need to change the size of an image (which is loaded into memory as an array of bytes) to shrink

Re: How to reliably detect an alias sequence?

2020-12-27 Thread sighoya via Digitalmars-d-learn
On Sunday, 27 December 2020 at 12:23:26 UTC, Max Samukha wrote: Given a name bound to an alias sequence, what is a reliable way to detect that? import std.meta: AliasSeq; alias a = AliasSeq!int; static if () { } __traits(isSame, a, AliasSeq!a) could work but doesn't, because it flattens

Re: Exchange of data through socket connection.

2020-12-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 December 2020 at 17:49:10 UTC, BPS wrote: void[] buff; incommingConn.receive(buff); this has no actual space to receive anything void[] buff = ['a', 's', 'd', 'f']; sock.send(buff); sock.receive(buff); and the return value needs to be

Exchange of data through socket connection.

2020-12-27 Thread BPS via Digitalmars-d-learn
Hello, i want to create basic example of 2 apps which will be exchanging data through socket connection. I have: server == import std.stdio; import std.string; import std.socket; void main() { auto sock = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP);

Re: Reading files using delimiters/terminators

2020-12-27 Thread Jesse Phillips via Digitalmars-d-learn
On Sunday, 27 December 2020 at 13:21:44 UTC, Rekel wrote: On Sunday, 27 December 2020 at 02:41:12 UTC, Jesse Phillips wrote: Unfortunately std.csv is character based and not string. https://dlang.org/phobos/std_csv.html#.csvReader But your use case sounds like splitter is more aligned with

Re: How to resize an image ? 樂

2020-12-27 Thread Guillaume Piolat via Digitalmars-d-learn
On Friday, 25 December 2020 at 20:59:03 UTC, vnr wrote: Hello  For a small "script" that generates printable files, I would need to change the size of an image (which is loaded into memory as an array of bytes) to shrink it to scale if it exceeds the A4 page size. To load the images into

Re: Get the code of any D-entity as string?

2020-12-27 Thread sighoya via Digitalmars-d-learn
On Sunday, 27 December 2020 at 14:40:01 UTC, Basile B. wrote: A more concrete example of what you are trying to achieve would allow to show the D way. What happens with your code example for the struct: ``` struct S { ulong[] a; @E(0) const int b=1; void v() const {return;}

Re: Get the code of any D-entity as string?

2020-12-27 Thread Basile B. via Digitalmars-d-learn
On Sunday, 27 December 2020 at 12:20:01 UTC, sighoya wrote: On Sunday, 27 December 2020 at 04:13:53 UTC, Max Haughton wrote: Not possible although implementing as a __trait would be about 15 lines I think. I think that too, and it would nicely reuse the work of the compiler to parse the

Re: Reading files using delimiters/terminators

2020-12-27 Thread oddp via Digitalmars-d-learn
On 27.12.20 01:13, Rekel via Digitalmars-d-learn wrote: For context, I'm trying this with the puzzle input of day 6 of this year's advent of code. (https://adventofcode.com/) For that specific puzzle I simply did: foreach (group; readText("input").splitter("\n\n")) { ... } Since the input is

Re: Reading files using delimiters/terminators

2020-12-27 Thread Rekel via Digitalmars-d-learn
On Sunday, 27 December 2020 at 02:41:12 UTC, Jesse Phillips wrote: Unfortunately std.csv is character based and not string. https://dlang.org/phobos/std_csv.html#.csvReader But your use case sounds like splitter is more aligned with your needs.

Re: visibility of private Class C in module named "C"; private variables in modules

2020-12-27 Thread kdevel via Digitalmars-d-learn
bugreport filed https://issues.dlang.org/show_bug.cgi?id=21508

state of digitalmars.com/webnews: PHP not available/wrong version?

2020-12-27 Thread kdevel via Digitalmars-d-learn
On http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D_id=87915 I found in Issue 1441 there is PHP source code shown instead of the message. Must `

How to reliably detect an alias sequence?

2020-12-27 Thread Max Samukha via Digitalmars-d-learn
Given a name bound to an alias sequence, what is a reliable way to detect that? import std.meta: AliasSeq; alias a = AliasSeq!int; static if () { } __traits(isSame, a, AliasSeq!a) could work but doesn't, because it flattens singletons, which means __traits(isSame, int, AliasSeq!int) is

Re: Get the code of any D-entity as string?

2020-12-27 Thread sighoya via Digitalmars-d-learn
On Sunday, 27 December 2020 at 04:13:53 UTC, Max Haughton wrote: Not possible although implementing as a __trait would be about 15 lines I think. I think that too, and it would nicely reuse the work of the compiler to parse the whole project. I think read only AST access in some form

Re: Get the code of any D-entity as string?

2020-12-27 Thread sighoya via Digitalmars-d-learn
On Saturday, 26 December 2020 at 21:45:41 UTC, Basile B. wrote: struct E {int a;} struct S { ulong[] a; @E(0) const int b; void v() const {} void v(int) const {} } string getDeclaration(T)() if (is(T == struct)) { import std.traits, std.meta; string result = "struct " ~

Re: Surprising behaviour of std.experimental.allocator

2020-12-27 Thread Saurabh Das via Digitalmars-d-learn
On Saturday, 26 December 2020 at 19:36:24 UTC, ag0aep6g wrote: On 26.12.20 13:59, ag0aep6g wrote: Looks like a pretty nasty bug somewhere in std.experimental.allocator or (less likely) the GC. Further reduced code: [...] Apparently, something calls deallocateAll on a Mallocator