Re: Generate docs for generated code?

2021-07-23 Thread wjoe via Digitalmars-d-learn
On Friday, 23 July 2021 at 10:54:33 UTC, Adam D Ruppe wrote: On Friday, 23 July 2021 at 10:04:55 UTC, wjoe wrote: Is there a way for the compiler to consider doc comments in auto generated, mixed in code? If you use my adrdox generator (which runs on the dpldocs.info website), it handles

Re: Generate docs for generated code?

2021-07-23 Thread wjoe via Digitalmars-d-learn
On Friday, 23 July 2021 at 10:42:22 UTC, user1234 wrote: On Friday, 23 July 2021 at 10:04:55 UTC, wjoe wrote: Is there a way for the compiler to consider doc comments in auto generated, mixed in code? E.g. ```D string fooImpl = q{ /// Bar does fancy things. const void bar() { /*do

Generate docs for generated code?

2021-07-23 Thread wjoe via Digitalmars-d-learn
Is there a way for the compiler to consider doc comments in auto generated, mixed in code? E.g. ```D string fooImpl = q{ /// Bar does fancy things. const void bar() { /*do something fancy*/ } }; /// This is Foo struct Foo(A, B, C) { mixin(fooImpl); } ``` So that the documentation for

Re: opIndexUnary post in-/decrement how to ?

2021-07-16 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 15:39:59 UTC, Tejas wrote: On Thursday, 15 July 2021 at 13:28:19 UTC, wjoe wrote: On Thursday, 15 July 2021 at 12:09:20 UTC, Tejas wrote: [...] The only way, for me, to explain the error message ```opIndex isn't an lvalue and can't be modified.``` for

Re: opIndexUnary post in-/decrement how to ?

2021-07-15 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 12:09:20 UTC, Tejas wrote: [...] Oh yes, that is what happens. I was trying to be a little concise. You are correct, this is what the code will look in the gory details (I believe) : ```d auto x = (auto e = i.opIndex(1), i.opIndexUnary("++")(1)/*this may or may

Re: Error with implicit cast of ^^=

2021-07-15 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 17:29:04 UTC, Ali Çehreli wrote: On 7/14/21 2:44 AM, wjoe wrote: >> x = (x ^^ y).to!(typeof(x)); >> } >> >> For example, run-time error if y == 7. > I was planning on adding support for over-/underflow bits but this is > much better. Thanks! If so, then there

Re: opIndexUnary post in-/decrement how to ?

2021-07-15 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 04:07:49 UTC, Tejas wrote: Your code ```d auto x = i[1]++; ``` Expands to: ```d auto x = (auto e = i[1]/*notice opIndex*/, ++i[1]/* notice opIndexUnary*/, return e;); ``` This doesn't happen with pre increment. No compiler shenanigans. Interesting to see it

Re: opIndexUnary post in-/decrement how to ?

2021-07-15 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 04:01:15 UTC, Tejas wrote: I'm so sorry all this was basically useless for you. I can't spend more time on this, so as a last resort I leave you this: https://dlang.org/phobos/std_bitmanip.html This is the official bit manipulation standard library, maybe it

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 16:13:35 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 15:08:56 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec work---pre-inc/dec return the modified value, post-inc/dec return the original value. [...] That makes a lot of sense now,

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:39:03 UTC, vit wrote: On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote: On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: [...] From doc: https://dlang.org/spec/operatoroverloading.html

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: I think it's a bug, because the following works: ```d import std.stdio; struct abc{ int[100] a; int opIndex(int index){ return a[index]; } int opIndexUnary(string s)(int index) if(s == "++"){

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: ``` {auto a = i[1] , ++i[1] , a} //note the , not the ;``` Sorry I can't provide something even more concrete. Yes I saw that, and I suppose it would work just fine if it were rewritten to just ```++i[1]```. What I'm struggling to

Re: catching segfault using try_ catch

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 00:10:59 UTC, seany wrote: On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote: On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: [...] true if it succeeded. [...] You mean transparently rerun some code? That's better done with the lowlevel

opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
I'm want to do something like this ```D part_int_t!(1,2,3) i; auto x = -i[0]; --i[1]; // 1 i[1]++; // 2 ``` I think the operator I need to overload would be opIndexUnary which I did. (1) compiles. (2) doesn't - the compiler complains that i.opIndex isn't an lvalue and can't be modified. The

Re: Error with implicit cast of ^^=

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Tuesday, 13 July 2021 at 15:14:26 UTC, Ali Çehreli wrote: On 7/13/21 4:12 AM, wjoe wrote: > ```D > byte x = some_val; > long y = some_val; > > x ^^= y; // Error: cannot implicitly convert expression > pow(cast(long)cast(int)x, y) of type long to byte [...] > I rewrote it to something like

Error with implicit cast of ^^=

2021-07-13 Thread wjoe via Digitalmars-d-learn
```D byte x = some_val; long y = some_val; x ^^= y; // Error: cannot implicitly convert expression pow(cast(long)cast(int)x, y) of type long to byte ``` Is there a way to do this via ^^= ? This is part of a unittest for opIndexOpAssign where the type of x is that of i.opIndex(_i). It's

Re: how to filter associative arrays with foreach ?

2021-06-21 Thread wjoe via Digitalmars-d-learn
On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote: I often need to iterate through a filtered collection (associative array) as following: ```d string strComputerIDunwanted = "WS2"; /// associative array key to exclude foreach (strComputerID, udtComputer; udtComputers) { ///

Re: Is it possible to set function attributes conditionally?

2021-06-04 Thread wjoe via Digitalmars-d-learn
On Friday, 4 June 2021 at 11:36:09 UTC, Adam D. Ruppe wrote: On Friday, 4 June 2021 at 11:33:32 UTC, wjoe wrote: This is a contrived example. In reality I would use this with custom array, hash map and other container implementations so I could use them in @nogc territory by just switching out

Is it possible to set function attributes conditionally?

2021-06-04 Thread wjoe via Digitalmars-d-learn
Hi, Consider Allocators, e.g.: ```d struct Mallocator { enum usesGC = false; /// implement alloc, free, etc. @nogc } struct GCAllocator { enum usesGC = true; /// implement alloc, free, etc. via the GC } ``` Now I want to have the function attributes set depending on the

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:08:47 UTC, data pulverizer wrote: On Wednesday, 23 September 2020 at 18:56:33 UTC, wjoe wrote: [...] Didn't think that the compiler didn't know but wasn't aware that you could use that information to statically dispatch. My mistake, I'll shut up now!

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:49:28 UTC, data pulverizer wrote: On Wednesday, 23 September 2020 at 18:37:45 UTC, wjoe wrote: [...] A class at compile time is it's own static type, OOP polymorphism is a runtime feature not compile time. You have to write your own traits for specific

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:50:28 UTC, H. S. Teoh wrote: Try this: interface I {} class C : I {} class D {} struct S {} pragma(msg, is(C : I)); // true pragma(msg, is(D : I)); // false pragma(msg, is(S : I)); // false So

How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
I have some similar functions: void register(C: IFoo)() { _insert!C(); } void register(C)() if (behavesLikeFoo!C) { _insert!C(); } There are more overloads with parameters so I want to merge them void register(C, ARGS...)(ARGS args) if (behavesLikeFoo!C || isInstanceOf!(C, IFoo)) {

Re: vibe.d: How to get the conent of a file upload ?

2020-09-20 Thread wjoe via Digitalmars-d-learn
On Sunday, 20 September 2020 at 00:36:30 UTC, Adam D. Ruppe wrote: [...] I browsed in your arsd docs a bit and I'll have a closer look at the CGI module a bit later. Your http2 module piqued my interest as it could come in handy some time later :) Looks like your modules cover everything I

Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread wjoe via Digitalmars-d-learn
On Sunday, 20 September 2020 at 00:36:30 UTC, Adam D. Ruppe wrote: [...] That's it - all the html and javascript are all auto-generated. Amazing :) Would even be more awesome if it provided a function which could be called from a custom main on top of the FancyMain. I find e.g. custom

Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread wjoe via Digitalmars-d-learn
On Saturday, 19 September 2020 at 20:17:06 UTC, aberba wrote: I personally (and many others in the industry... judging by popularity of express (node.js) and the plentiful third-party libraries,..do prefer the router.get() design. Also having everything abstracted in a convenient and

Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread wjoe via Digitalmars-d-learn
On Saturday, 19 September 2020 at 19:27:40 UTC, Steven Schveighoffer wrote: [...] This used to be the expected way to set up vibe (using module constructors). And vibe would provide its own main function. I *think* the idea was to allow registration of different handlers in their respective

Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 22:21:52 UTC, Adam D. Ruppe wrote: On Friday, 18 September 2020 at 22:02:07 UTC, aberba wrote: [...] I actually added *exactly* this to cgi.d in... 2010 if I remember right. I even kinda documented it:

Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 22:31:09 UTC, mw wrote: On Friday, 18 September 2020 at 00:07:12 UTC, wjoe wrote: Are there other frameworks besides vibe that can do what I want? Just FYI, there is also: https://code.dlang.org/packages/hunt-framework I never used myself, you need to

Re: vibe.d: How to get the conent of a file upload ?

2020-09-19 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 22:02:07 UTC, aberba wrote: [...] That's what I was trying to answer. When Steve said meh, he probably didn't get what I said. Probably its because of my typos. This sort of convenience and productivity benefit is part of why I use Node.Js in the job when I

Re: dub: Is it possible to have a library target and depend on it in the same dub config?

2020-09-18 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 14:15:27 UTC, Steven Schveighoffer wrote: On 9/18/20 7:38 AM, wjoe wrote: [...] There are other options. for instance dub (the project) has a library and an application. the config looks like this: configuration "application" { targetType

Re: dub: Is it possible to have a library target and depend on it in the same dub config?

2020-09-18 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 14:01:55 UTC, Mike Parker wrote: On Friday, 18 September 2020 at 12:28:30 UTC, wjoe wrote: 2 issues though. - It doesn't build the library automatically, and You'll have to invoke dub once for each config. Just slap both commands in a script. - Linking

Re: vibe.d: How to get the conent of a file upload ?

2020-09-18 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 12:58:29 UTC, Steven Schveighoffer wrote: On 9/18/20 8:39 AM, Steven Schveighoffer wrote: But again, solved with an enhancement that allows you to process the data in your code. I'll file the enhancement request for you, as I think it's a nice addition.

Re: vibe.d: How to get the conent of a file upload ?

2020-09-18 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 12:39:43 UTC, Steven Schveighoffer wrote: On 9/17/20 8:07 PM, wjoe wrote: [...] See the code here: https://github.com/vibe-d/vibe.d/blob/ebebfa827f568cc9bced4bec2b66edc043a8adf7/inet/vibe/inet/webform.d#L311 [...] No, not at the moment. Which is why I was

Re: dub: Is it possible to have a library target and depend on it in the same dub config?

2020-09-18 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 12:03:45 UTC, Mike Parker wrote: On Friday, 18 September 2020 at 11:38:14 UTC, wjoe wrote: Something like this: configuration "lib" { targetType "dynamicLibrary" sourceDir "source/lib/" } configuration "app" { targetType "executable" sourceFiles

Re: vibe.d: How to get the conent of a file upload ?

2020-09-18 Thread wjoe via Digitalmars-d-learn
On Friday, 18 September 2020 at 11:44:39 UTC, Atwork wrote: On Friday, 18 September 2020 at 00:07:12 UTC, wjoe wrote: And if not, how is data processed with a 10mb file upload followed by a few number fields ? It needs to read all of the file data to get to the other data fields, doesn't it ?

dub: Is it possible to extend or specialize configurations ?

2020-09-18 Thread wjoe via Digitalmars-d-learn
configuration "app" { versions "CLI" target "executable" ... } configuration "guiapp" : "app" { versions "GUI" sourceFiles "source/gui.d" } The guiapp should basically inherit the "app" configuration and extend/override whatever else is needed/different.

dub: Is it possible to have a library target and depend on it in the same dub config?

2020-09-18 Thread wjoe via Digitalmars-d-learn
Something like this: configuration "lib" { targetType "dynamicLibrary" sourceDir "source/lib/" } configuration "app" { targetType "executable" sourceFiles "source/app.d" linkWith "lib" } I found subConfiguration in the docs but that seems to be related to external dependencies.

Re: vibe.d: How to get the conent of a file upload ?

2020-09-17 Thread wjoe via Digitalmars-d-learn
On Thursday, 17 September 2020 at 22:33:46 UTC, Steven Schveighoffer wrote: On 9/17/20 6:13 PM, aberba wrote: On Thursday, 17 September 2020 at 21:57:37 UTC, Steven Schveighoffer wrote: On 9/17/20 1:08 PM, wjoe wrote: [...] the `files` property actually does the processing only when you

Re: Building LDC runtime for a microcontroller

2020-09-17 Thread wjoe via Digitalmars-d-learn
On Thursday, 17 September 2020 at 19:27:41 UTC, Adam D. Ruppe wrote: fyi my baby was just born i'll come back to this but it might be a day or two congratulations! All the best for your family :)

Re: vibe.d: How to get the conent of a file upload ?

2020-09-17 Thread wjoe via Digitalmars-d-learn
On Thursday, 17 September 2020 at 16:32:55 UTC, WebFreak001 wrote: On Thursday, 17 September 2020 at 16:00:33 UTC, wjoe wrote: I found this [1] but unfortunately the post this refers to is a dead link and the content, unfortunately, didn't tell me anything that I didn't already find in the

vibe.d: How to get the conent of a file upload ?

2020-09-17 Thread wjoe via Digitalmars-d-learn
I found this [1] but unfortunately the post this refers to is a dead link and the content, unfortunately, didn't tell me anything that I didn't already find in the docs. What I can get from the form is the form fields with content, the field name for the file upload and the file name. But the

Re: Why is BOM required to use unicode in tokens?

2020-09-16 Thread wjoe via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 01:49:13 UTC, James Blachly wrote: I wish to write a function including ∂x and ∂y (these are trivial to type with appropriate keyboard shortcuts - alt+d on Mac), but without a unicode byte order mark at the beginning of the file, the lexer rejects the tokens.

Re: Why is there no throws, @gc, impure, mutable ?

2020-09-07 Thread wjoe via Digitalmars-d-learn
On Monday, 7 September 2020 at 11:44:40 UTC, Paul Backus wrote: On Monday, 7 September 2020 at 11:25:15 UTC, wjoe wrote: It's easy to declare the entire module @safe and functions which can't be can be declared @system. However there is const, immutable, pure, @nogc and nothrow but no mutable,

Why is there no throws, @gc, impure, mutable ?

2020-09-07 Thread wjoe via Digitalmars-d-learn
It's easy to declare the entire module @safe and functions which can't be can be declared @system. However there is const, immutable, pure, @nogc and nothrow but no mutable, impure, @gc and throws. Why is that ?

Re: Reading from stdin significantly slower than reading file directly?

2020-08-13 Thread wjoe via Digitalmars-d-learn
On Thursday, 13 August 2020 at 07:08:21 UTC, Jon Degenhardt wrote: Test Elapsed System User --- -- tsv-select -f 2,3 FILE 10.280.42 9.85 cat FILE | tsv-select -f 2,311.101.45 10.23 cut -f 2,3 FILE

Re: Could someone calrify reserving and collecting memory via the Garbabe Collector ?

2020-08-06 Thread wjoe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 17:18:12 UTC, rikki cattermole wrote: On 07/08/2020 5:12 AM, wjoe wrote: There's core.memory.GC.reserve which requests memory from the OS. Basically pre-allocating memory for the GC heap. Is the GC heap shared among all threads ? That is up to the GC

Could someone calrify reserving and collecting memory via the Garbabe Collector ?

2020-08-06 Thread wjoe via Digitalmars-d-learn
There's core.memory.GC.reserve which requests memory from the OS. Basically pre-allocating memory for the GC heap. Is the GC heap shared among all threads ? E.g what happens if I GC.reserve(4.MiB) ? Is it 4 MiB in total or per thread ? And is it correct that even if I call GC.disable, the GC

Re: dynamic array .length vs .reserve - what's the difference?

2020-08-03 Thread wjoe via Digitalmars-d-learn
On Saturday, 1 August 2020 at 16:04:01 UTC, Steven Schveighoffer wrote: On 7/31/20 12:32 PM, wjoe wrote: On Friday, 31 July 2020 at 04:28:57 UTC, Ali Çehreli wrote: Another option, which is curiously said to be more performant in memory allocation than native arrays, is std.array.Appender.

Re: dynamic array .length vs .reserve - what's the difference?

2020-07-31 Thread wjoe via Digitalmars-d-learn
On Friday, 31 July 2020 at 04:28:57 UTC, Ali Çehreli wrote: Yes but the "sharing being terminated" phrase was my attempt at explaining things, which did not catch on. :) Real shame. I quite like it - especially if you say it out loud with an Austrian accent :) Another option, which is

Re: dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread wjoe via Digitalmars-d-learn
On Thursday, 30 July 2020 at 16:33:22 UTC, Ali Çehreli wrote: On 7/30/20 8:58 AM, wjoe wrote:     b.reserve(n);     b.length = n; There may be something that I don't know but I think assigning to the .length property alone should be the same as reserving and then assigning.

dynamic array .length vs .reserve - what's the difference?

2020-07-30 Thread wjoe via Digitalmars-d-learn
I just stumbled upon code like this: struct Foo(T) { T[] b; this(int n) { b.reserve(n); b.length = n; } } .reserve looks redundant. The docs are explaining .length nicely, however lack any specifics about reserve. Changing the length of an array may relocate

Re: Good way to send/receive UDP packets?

2020-07-28 Thread wjoe via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 15:01:08 UTC, Kagamin wrote: On Monday, 27 July 2020 at 09:41:44 UTC, wjoe wrote: But it's possible when bound with the socket option SO_REUSEPORT (at least that's the name of the flag on linux since 3.9). The docs say it can't be used to hijack an address. This

Re: Why are std.bitmanip.bitfields so big ?

2020-07-28 Thread wjoe via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 13:00:12 UTC, Steven Schveighoffer wrote: On 7/28/20 5:46 AM, MoonlightSentinel wrote: On Tuesday, 28 July 2020 at 09:28:27 UTC, wjoe wrote: It was run on the doc page. I suppose the examples are wrapped in a unittest block? Indeed, see

Re: Why are std.bitmanip.bitfields so big ?

2020-07-28 Thread wjoe via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 09:46:01 UTC, MoonlightSentinel wrote: On Tuesday, 28 July 2020 at 09:28:27 UTC, wjoe wrote: It was run on the doc page. I suppose the examples are wrapped in a unittest block? Indeed, see

Re: Why are std.bitmanip.bitfields so big ?

2020-07-28 Thread wjoe via Digitalmars-d-learn
On Monday, 27 July 2020 at 12:52:53 UTC, Steven Schveighoffer wrote: On 7/27/20 5:49 AM, wjoe wrote: struct A {     mixin(bitfields!(    bool, "flag1",    1,    bool, "flag2",    1,    uint, "", 6)); } Is this inside a function? If so, put `static` on it. What you are

Why are std.bitmanip.bitfields so big ?

2020-07-27 Thread wjoe via Digitalmars-d-learn
From the API documentation: Create a bitfield pack of eight bits, which fit in one ubyte. [...] struct A { mixin(bitfields!( bool, "flag1",1, bool, "flag2",1, uint, "", 6)); } A a; writeln(a.flag1); // 0 a.flag1 = 1; writeln(a.flag1); // 1 a.flag1 = 0;

Re: Good way to send/receive UDP packets?

2020-07-27 Thread wjoe via Digitalmars-d-learn
On Thursday, 23 July 2020 at 13:29:47 UTC, Kagamin wrote: On Wednesday, 22 July 2020 at 16:14:24 UTC, wjoe wrote: If you send a UDP datagram to a single address, however, it will still be delivered to every program on that PC which receives UDP datagrams from that port. Normally binding two

Re: Good way to send/receive UDP packets?

2020-07-22 Thread wjoe via Digitalmars-d-learn
On Wednesday, 22 July 2020 at 16:14:24 UTC, wjoe wrote: When receiving packets, the IP header contains the destination address of your public IP (the router), which it will translate to the local address according to the port forwarding setup. Pardon me, I meant to say according to the

Re: Good way to send/receive UDP packets?

2020-07-22 Thread wjoe via Digitalmars-d-learn
On Wednesday, 22 July 2020 at 15:26:23 UTC, Dukc wrote: On Wednesday, 22 July 2020 at 13:17:11 UTC, wjoe wrote: - Choosing a port which isn't in use right now isn't good enough because a few minutes later there may be another program using it, too, and for the same reason. But doesn't the

Re: Good way to send/receive UDP packets?

2020-07-22 Thread wjoe via Digitalmars-d-learn
On Tuesday, 21 July 2020 at 18:35:34 UTC, notna wrote: well, I guess all your remarks are true... and irrelevant at the same time. please go back and read his first post starts with "I have a project where I need to take and send UDP packets over the Internet"... ... and continues

Re: Good way to send/receive UDP packets?

2020-07-21 Thread wjoe via Digitalmars-d-learn
On Sunday, 19 July 2020 at 09:48:24 UTC, notna wrote: Someone once wrote about a UDP library, which was used to sync data to somewhere in APAC (Hongkong?) and by doing so the data transfer was magnitudes faster then before (over TCP)... In the best case scenario, and orders of magnitude

Re: miscellaneous array questions...

2020-07-21 Thread wjoe via Digitalmars-d-learn
On Monday, 20 July 2020 at 22:05:35 UTC, WhatMeWorry wrote: 2) "The total size of a static array cannot exceed 16Mb" What limits this? And with modern systems of 16GB and 32GB, isn't 16Mb excessively small? (an aside: shouldn't that be 16MB in the reference instead of 16Mb? that is, Doesn't

Re: What's the point of static arrays ?

2020-07-13 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 21:24:08 UTC, Ali Çehreli wrote: What is important is overhead: That's the major point I took from all this. Thanks for your effort. And thanks everybody else, too, I really appreciate it.

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 14:20:15 UTC, wjoe wrote: On Friday, 10 July 2020 at 10:47:49 UTC, psycha0s wrote: On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: A static array resides in this memory (with a fixed length, so a length needn't be stored because bounds can be checked at compile

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 11:13:51 UTC, Stanislav Blinov wrote: On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: So many awesome answers, thank you very much everyone! Less overhead, Using/needing it to interface with something else, and Efficiency are very good points. However stack

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 10:47:49 UTC, psycha0s wrote: On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: However stack memory needs to be allocated at program start. I don't see a huge benefit in allocation speed vs. heap pre-allocation, or is there? I mean 1 allocation vs 2 isn't going

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Thursday, 9 July 2020 at 17:15:26 UTC, Jonathan M Davis wrote: On Thursday, July 9, 2020 10:21:41 AM MDT H. S. Teoh via Digitalmars-d-learn wrote: > - Assignment copies the whole array, as in int[5] a; auto b > = a; Sometimes this is desirable. Consider the 3D game example. Suppose

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
So many awesome answers, thank you very much everyone! Less overhead, Using/needing it to interface with something else, and Efficiency are very good points. However stack memory needs to be allocated at program start. I don't see a huge benefit in allocation speed vs. heap pre-allocation, or

What's the point of static arrays ?

2020-07-09 Thread wjoe via Digitalmars-d-learn
+ The size is known at compile time. vs. - Can neither grow nor shrink them - Can't append elements - Can't remove elements - Can't slice them - Can't range them - Assignment copies the whole array, as in int[5] a; auto b = a; - Size is limited by stack - Stack overflow issues Some of the

Re: What's the best way to find out which exceptions may be thrown ?

2020-06-03 Thread wjoe via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 07:19:45 UTC, Luis wrote: On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote: Could you please elaborate why checked exceptions are more annoying? Have like 3 functions : A calls B, B calls C . [...] I work daily with Java, and it's pretty annoying. That

Re: What's the best way to find out which exceptions may be thrown ?

2020-06-03 Thread wjoe via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 13:58:13 UTC, Bienlein wrote: On Wednesday, 27 May 2020 at 11:40:00 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote: [...] For me, it's because they require all functions that touch them to either try/catch or include an exception

Re: What's the best way to find out which exceptions may be thrown ?

2020-05-27 Thread wjoe via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 11:40:00 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote: On Wednesday, 27 May 2020 at 10:01:33 UTC, Mike Parker wrote: Could you please elaborate why checked exceptions are more annoying? For me, it's because they require all

Re: What's the best way to find out which exceptions may be thrown ?

2020-05-27 Thread wjoe via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 10:01:33 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:56:07 UTC, wjoe wrote: The problem with catch(Exception) is that it's run time whereas I'd like to know compile time which exception may possibly be thrown. So I take it the only way to find out

Re: What's the best way to find out which exceptions may be thrown ?

2020-05-27 Thread wjoe via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 09:44:56 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:42:58 UTC, Mike Parker wrote: I should add that if you're only catching specific exceptions in a `nothrow` function, then it isn't `nothrow`. You have to catch Exception because D does not have

Re: What's the best way to find out which exceptions may be thrown ?

2020-05-27 Thread wjoe via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 09:44:56 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:42:58 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:40:08 UTC, wjoe wrote: The compiler will complain that bar(int) isn't nothrow. What's the best way to find out which Exceptions aren't

What's the best way to find out which exceptions may be thrown ?

2020-05-27 Thread wjoe via Digitalmars-d-learn
nothrow void foo() { bar(4); } void bar(int a) { if (a ==1) throw new Exception1(); else if (a == 2) throw new Exception2(); baz(); } void baz() { if (whatever) throw new Exception3(); } The compiler will complain that bar(int) isn't nothrow. What's the best way to

Re: final struct ?

2020-05-20 Thread wjoe via Digitalmars-d-learn
On Wednesday, 20 May 2020 at 04:40:33 UTC, user1234 wrote: On Tuesday, 19 May 2020 at 10:29:51 UTC, wjoe wrote: On Tuesday, 19 May 2020 at 10:08:37 UTC, user1234 wrote: [...] Thank you. A little sample to show you more cases of attributes that have no effect: --- struct Foo {

Re: final struct ?

2020-05-19 Thread wjoe via Digitalmars-d-learn
On Tuesday, 19 May 2020 at 10:08:37 UTC, user1234 wrote: On Tuesday, 19 May 2020 at 10:01:34 UTC, wjoe wrote: [...] It has no purpose. In D many attributes are allowed even if they have no meaning. D-Scanner checks this kind of stuff, to some extent, but not the compiler. Thank you.

final struct ?

2020-05-19 Thread wjoe via Digitalmars-d-learn
As I was reading a few source files of a library I found dozens of final struct declarations like this: final struct Foo { const pure final nothrow bar() { ... } } What's this supposed to express ? A final class is a class that can't be subclassed - structs can't be subclassed, so does

Re: Best way to refer to the type of a struct inside itself ?

2020-05-15 Thread wjoe via Digitalmars-d-learn
On Friday, 15 May 2020 at 15:24:32 UTC, Ali Çehreli wrote: On 5/15/20 8:04 AM, Paul Backus wrote: [...] Yes, that is a consistent way of explaining it. :) As an off-topic trivia, the same feature is in C++ as well: [...] Ali Awesome. Thank you Ali and Paul :)

Re: Best way to refer to the type of a struct inside itself ?

2020-05-15 Thread wjoe via Digitalmars-d-learn
On Friday, 15 May 2020 at 13:52:38 UTC, Paul Backus wrote: On Friday, 15 May 2020 at 13:47:43 UTC, wjoe wrote: struct Foo(A, B, C, size_t a, size_t b) { alias foo_t = Foo!(A, B, C, a, b); // is there a better way to get foo_t ? } typeof(this) Thanks :)

Best way to refer to the type of a struct inside itself ?

2020-05-15 Thread wjoe via Digitalmars-d-learn
struct Foo(A, B, C, size_t a, size_t b) { alias foo_t = Foo!(A, B, C, a, b); // is there a better way to get foo_t ? }

Compiler bug ? -preview=intpromote and Integral promotion rules not being followed for unary + - ~ operators

2020-05-14 Thread wjoe via Digitalmars-d-learn
I have a container which provides access to data via a handle. For book keeping I calculate some bitmasks. Previously, when the handle type as well as the constants were uint, everything compiled fine. Today I added a template parameter to be able to specify the handle type and I ran into this

Re: Easy way to format int in pragma msg ?

2020-05-14 Thread wjoe via Digitalmars-d-learn
On Thursday, 14 May 2020 at 10:58:34 UTC, WebFreak001 wrote: On Thursday, 14 May 2020 at 09:49:15 UTC, wjoe wrote: Is there an easy way to print an int in hexadecimal, octal or binary representation ? The documentation on pragma(msg, ...) and a quick web search didn't provide an answer.

Easy way to format int in pragma msg ?

2020-05-14 Thread wjoe via Digitalmars-d-learn
Is there an easy way to print an int in hexadecimal, octal or binary representation ? The documentation on pragma(msg, ...) and a quick web search didn't provide an answer.

Re: Error running concurrent process and storing results in array

2020-05-13 Thread wjoe via Digitalmars-d-learn
On Friday, 8 May 2020 at 13:43:40 UTC, data pulverizer wrote: [...] I also chose kernel matrix calculations, you can't always call a library, sometimes you just need to write performant code. Aren't kernel function calls suffering a context switch though ?

Re: How to port C++ std::is_reference to D ?

2020-05-13 Thread wjoe via Digitalmars-d-learn
On Monday, 11 May 2020 at 19:08:09 UTC, Q. Schroll wrote: [...] 1. You can have variables ("data members") of reference type in structs. (They work like head-const pointers; if D had head-const or at least head-const pointers, those would be practically the same, only that references cannot

Re: How to port C++ std::is_reference to D ?

2020-05-07 Thread wjoe via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 16:01:37 UTC, Paul Backus wrote: On Wednesday, 6 May 2020 at 09:40:47 UTC, wjoe wrote: yes, I did read the spec. I read the language spec on traits as well as std.traits docs as well as searching the internet for a solution since day before yesterday. But I couldn't

How to port C++ std::is_reference to D ?

2020-05-06 Thread wjoe via Digitalmars-d-learn
Hello, I'm choking on a piece of C++ I have no idea about how to translate to D. template typename std::enable_if< std::is_const::value == true, void>::type* = nullptr> constexpr const char *modifier() const { return "[in] "; } template typename

Re: How to port C++ std::is_reference to D ?

2020-05-06 Thread wjoe via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 09:19:10 UTC, drug wrote: 06.05.2020 12:07, wjoe пишет: Hello, I'm choking on a piece of C++ I have no idea about how to translate to D.   template     typename std::enable_if< std::is_const::value == true, void>::type* = nullptr>     constexpr const

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-14 Thread wjoe via Digitalmars-d-learn
On Friday, 13 March 2020 at 20:31:16 UTC, Steven Schveighoffer wrote: On 3/13/20 4:22 PM, wjoe wrote: I would expect that something could be written to turn a signature string into a mangling and also provide the correct type upon return. Something like: auto f = getFunction!(@safe void

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
On Friday, 13 March 2020 at 18:30:51 UTC, H. S. Teoh wrote: On Fri, Mar 13, 2020 at 06:11:01PM +, wjoe via Digitalmars-d-learn wrote: On Friday, 13 March 2020 at 17:05:32 UTC, Mike Parker wrote: > On Friday, 13 March 2020 at 16:11:53 UTC, wjoe wrote: > > On Friday, 13 March 2020 at

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
On Friday, 13 March 2020 at 17:05:32 UTC, Mike Parker wrote: On Friday, 13 March 2020 at 16:11:53 UTC, wjoe wrote: On Friday, 13 March 2020 at 16:04:06 UTC, Mike Parker wrote: On Friday, 13 March 2020 at 15:16:06 UTC, wjoe wrote: bindSymbol(, "VersionOfAPI"); } Is it possible to

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
On Friday, 13 March 2020 at 16:04:06 UTC, Mike Parker wrote: On Friday, 13 March 2020 at 15:16:06 UTC, wjoe wrote: bindSymbol(, "VersionOfAPI"); } Is it possible to convince the compiler to look the other way while binding @safe functions from the plugin ? It probably has nothing to

Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread wjoe via Digitalmars-d-learn
I've got a plug-in which is a shared library. Like this module plugin; @safe int VersionOfAPI() { return 1; } this is builds to plugin.so in main.d I'm loading the plugin and bind the those functions like so: module app; @safe: alias apiverfn = int function(); apiverfn apiVersion;

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 15:19:39 UTC, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 15:05:56 UTC, wjoe wrote: But didn't like the string part and that's when I introduced the alias fn because I figured maybe it's possible to do something like: factory.dispatch!(Bitmap.load)(handle,

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 14:14:04 UTC, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?!

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 13:55:25 UTC, Steven Schveighoffer wrote: On 3/6/20 6:51 AM, wjoe wrote: On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) {     auto opDispatch(T,

  1   2   >