Re: Why is time_t defined as a 32-bit type on Windows?

2020-08-06 Thread Andrej Mitrovic via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 16:13:19 UTC, Andrej Mitrovic wrote: ``` C:\dev> rdmd -m64 --eval="import core.stdc.time; writeln(time_t.sizeof);" 4 ``` According to MSDN this should not be the case: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/time-time32-time64?view=vs-20

Re: core.thread vs std.concurrency - which of them to use?

2020-08-06 Thread Petar via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:13:28 UTC, Victor L Porton wrote: When to use core.thread and when std.concurrency for multithreading in applications? Is one of them a preferred way? Druntime's core.thread sets the foundation for D's multi-threading (or at least the non-betterC foundation). O

Re: I just discovered an alternative use of the `in`-operator

2020-08-06 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 6 August 2020 at 21:50:06 UTC, Per Nordlöw wrote: I just discovered that the is-operator can be used as in template ElementType(R) { static if (is(typeof(R.init.front.init) T)) alias ElementType = T; else alias ElementType = void; } . Very powerful. Is this

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 implementat

I just discovered an alternative use of the `in`-operator

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
I just discovered that the is-operator can be used as in template ElementType(R) { static if (is(typeof(R.init.front.init) T)) alias ElementType = T; else alias ElementType = void; } . Very powerful. Is this documented?

Re: I just discovered an alternative use of the `in`-operator

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 21:50:06 UTC, Per Nordlöw wrote: I just discovered that the is-operator can be used as in ... Doh, title should of course be I just discovered an alternative use of `is`-expressions.

Re: Dub can't find and download packages

2020-08-06 Thread vanaur via Digitalmars-d-learn
Thank you for your comments :) I tried again this morning, and the problem persisted... I have just reinstalled my D environment. It must have been badly installed, because now everything is working normally. Looking at the installation files, I saw that there was a dependency to libcurl. Ma

Re: Non-recursive maxSizeOf

2020-08-06 Thread Ali Çehreli via Digitalmars-d-learn
On 8/6/20 4:44 AM, Per Nordlöw wrote: On Thursday, 6 August 2020 at 01:13:28 UTC, Ali Çehreli wrote: Boring in D. :p template maxSizeOf(T...) {   enum maxSizeOf = compute();   auto compute() {     size_t result;     static foreach (t; T) {   if (t.sizeof > result) {     result = t.size

Re: Template constraint on alias template parameter.

2020-08-06 Thread jmh530 via Digitalmars-d-learn
On Thursday, 6 August 2020 at 18:09:50 UTC, ag0aep6g wrote: [snip] `is(...)` only works on types. You're looking for `__traits(isSame, T, Foo)`. For `is(T!U == Foo!U, U)` to work, the compiler would have to guess U. If the first guess doesn't work, it would have to guess again, and again, a

Re: Template constraint on alias template parameter.

2020-08-06 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 6 August 2020 at 16:01:35 UTC, jmh530 wrote: The code below compiles, but I want to put an additional constraint on the `test` function is only called with a Foo struct. I tried things like is(T == Foo) and is(T : Foo), but those don't work. However, something like is(T!int : Foo

Re: Template constraint on alias template parameter.

2020-08-06 Thread jmh530 via Digitalmars-d-learn
On Thursday, 6 August 2020 at 16:01:35 UTC, jmh530 wrote: [snip] It seems as if the T is properly Foo(T) and can only be instantiated with actual types. Something like below works and might work for me. template test(alias T) if (__traits(isTemplate, T)) { void test(U)(U x)

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

2020-08-06 Thread rikki cattermole via Digitalmars-d-learn
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 implementation. And is it correct that even if I call GC.disable, the GC may st

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

Template constraint on alias template parameter.

2020-08-06 Thread jmh530 via Digitalmars-d-learn
The code below compiles, but I want to put an additional constraint on the `test` function is only called with a Foo struct. I tried things like is(T == Foo) and is(T : Foo), but those don't work. However, something like is(T!int : Foo!int) works, but is(T!U == Foo!U, U) doesn't. Any idea why

Re: Non-recursive maxSizeOf

2020-08-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/6/20 9:23 AM, Adam D. Ruppe wrote: On Thursday, 6 August 2020 at 13:18:40 UTC, Per Nordlöw wrote:     mixin(T.stringof ~ " _store" ~ T.mangleof ~ Never ever use mixin(T.stringof). Always just use mixin("T") instead. mixin("T _store", T.mangleof /* or just idx is gonna be bett

Re: Non-recursive maxSizeOf

2020-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 06, 2020 at 01:07:14PM +, Per Nordlöw via Digitalmars-d-learn wrote: [...] > However, your solution > > template maxSize(T...) > { > align(1) union Impl { T t; } > enum maxSize = Impl.sizeof; > } > > fails as > > variable `std.variant.maxSize!(void, string).Impl.__t_fi

Re: Non-recursive maxSizeOf

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 13:18:40 UTC, Per Nordlöw wrote: Can somebody find a better alternative? Let's continue discussion at https://github.com/dlang/phobos/pull/7582

Re: Non-recursive maxSizeOf

2020-08-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 13:18:40 UTC, Per Nordlöw wrote: mixin(T.stringof ~ " _store" ~ T.mangleof ~ Never ever use mixin(T.stringof). Always just use mixin("T") instead. mixin("T _store", T.mangleof /* or just idx is gonna be better */,";"); Though I doubt this is g

Re: Non-recursive maxSizeOf

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 13:07:14 UTC, Per Nordlöw wrote: Do you have any simple solution to this, H. S. Teoh? I also tried template maxSize(Ts...) { align(1) union Impl { // See_Also: https://forum.dlang.org/thread/wbpnncxepehgcswhu...@forum.dlang.org?page=1 sta

Re: Non-recursive maxSizeOf

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 12:51:22 UTC, H. S. Teoh wrote: Of course. In fact, it's trivial: -- template maxSizeOf(T...) { align(1) union Impl { T t; } enum maxSizeOf = Impl.sizeof; } I originally copied my original version of `maxSizeOf` from `s

Re: Non-recursive maxSizeOf

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 12:51:22 UTC, H. S. Teoh wrote: Of course. In fact, it's trivial: -- template maxSizeOf(T...) { align(1) union Impl { T t; } enum maxSizeOf = Impl.sizeof; } Clever. Thanks

Re: Non-recursive maxSizeOf

2020-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thursday, 6 August 2020 at 00:58:39 UTC, Per Nordlöw wrote: Is it possible to implement template maxSizeOf(T...) { static if (T.length == 1) enum size_t maxSizeOf = T[0].sizeof; else { enum size_t firstSize = T[0].sizeof; enum size_t maxSizeRest = maxSizeOf

Re: Files and UTF

2020-08-06 Thread Mike Surette via Digitalmars-d-learn
On Thursday, 6 August 2020 at 07:24:23 UTC, WebFreak001 wrote: On Thursday, 6 August 2020 at 07:19:37 UTC, WebFreak001 wrote: [...] In line 11 in my example code this makes a better, safer if than `if (s.length)`: if (s.length && s[$ - 1] == '\n') s = s[0 .. $ - 1]; Note that I only need to

Re: Non-recursive maxSizeOf

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:13:28 UTC, Ali Çehreli wrote: Boring in D. :p template maxSizeOf(T...) { enum maxSizeOf = compute(); auto compute() { size_t result; static foreach (t; T) { if (t.sizeof > result) { result = t.sizeof; } } return result;

Re: Dub can't find and download packages

2020-08-06 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 17:32:49 UTC, vanaur wrote: My concern is thus the following: I can't add packages to my project, Dub warns me that they are not available. For the example, I try to add this dependency (https://code.dlang.org/packages/pegged) with the following command: dub

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-06 Thread Martin Tschierschke via Digitalmars-d-learn
On Monday, 3 August 2020 at 15:33:54 UTC, Dominikus Dittes Scherkl wrote: [...] For really long expressions you could also split it on multiple lines: c = (b_expression == 0) ? (d_longer_expression) : (a_expression/b_expression); +1 looks clean!

Re: Files and UTF

2020-08-06 Thread WebFreak001 via Digitalmars-d-learn
On Thursday, 6 August 2020 at 07:19:37 UTC, WebFreak001 wrote: [...] In line 11 in my example code this makes a better, safer if than `if (s.length)`: if (s.length && s[$ - 1] == '\n') s = s[0 .. $ - 1]; Note that I only need to do this because of the readln API, it would be much safer and

Re: Files and UTF

2020-08-06 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 17:39:36 UTC, Mike Surette wrote: In my efforts to learn D I am writing some code to read files in different UTF encodings with the aim of having them end up as UTF-8 internally. As a start I have the following code: import std.stdio; import std.file; void main(