Re: Invoking the compiler during runtime

2020-08-05 Thread cy via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 06:02:58 UTC, cy wrote: Some way to import the compiler itself, instead of calling it in a subprocess? Well, I did find this: https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ But it's pretty advanced... probably just invoking dmd w

can't access an alias created inside an if statement

2020-08-05 Thread Flade via Digitalmars-d-learn
I have used an if-else statement to create an alias to avoid code duplication but it doesn't let me access it outside the if statement. Is there a way to solve this?

Re: can't access an alias created inside an if statement

2020-08-05 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:05:36 UTC, Flade wrote: I have used an if-else statement to create an alias to avoid code duplication but it doesn't let me access it outside the if statement. Is there a way to solve this? You're probably looking for static if: static if (useAlias) {

Re: can't access an alias created inside an if statement

2020-08-05 Thread Flade via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:25:23 UTC, Simen Kjærås wrote: On Wednesday, 5 August 2020 at 09:05:36 UTC, Flade wrote: I have used an if-else statement to create an alias to avoid code duplication but it doesn't let me access it outside the if statement. Is there a way to solve this? You'

Re: can't access an alias created inside an if statement

2020-08-05 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:32:58 UTC, Flade wrote: Thanks! You see it should work but the thing is. I'm using it inside a function. I'm checking for one of the function's parameter (if parameter == false) and it says that "the variable `parameter` cannot be read at compile time. Do you

Re: can't access an alias created inside an if statement

2020-08-05 Thread Flade via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:39:47 UTC, Simen Kjærås wrote: On Wednesday, 5 August 2020 at 09:32:58 UTC, Flade wrote: Thanks! You see it should work but the thing is. I'm using it inside a function. I'm checking for one of the function's parameter (if parameter == false) and it says that "

Re: D on lm32-CPU: string argument on stack instead of register

2020-08-05 Thread FeepingCreature via Digitalmars-d-learn
On Tuesday, 4 August 2020 at 17:36:53 UTC, Michael Reese wrote: Thanks for suggesting! I tried, and the union works as well, i.e. the function args are registered. But I noticed another thing about all workarounds so far: Even if calls are inlined and arguments end up on the stack, the linker p

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

2020-08-05 Thread Andrej Mitrovic via Digitalmars-d-learn
``` 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-2019 time is a wrapper for _time64 and **time_t is, by default, equiv

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

2020-08-05 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: Invoking the compiler during runtime

2020-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 05, 2020 at 06:02:58AM +, cy via Digitalmars-d-learn wrote: > D's compile-time-execution is fantastic, but there are some times when > I'd like to examine the generated code, or produce code that needs to > pass through earlier phases before CTFE, or do AST stuff. Sometimes I > simp

Dub can't find and download packages

2020-08-05 Thread vanaur via Digitalmars-d-learn
Hello. I'm starting to use D, and therefore Dub. I didn't find a more suitable category than this one in the forum to ask my question, I'm sorry if it is not the most suitable. My concern is thus the following: I can't add packages to my project, Dub warns me that they are not available. For

Files and UTF

2020-08-05 Thread Mike Surette via Digitalmars-d-learn
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(string[] args) { if (args.length == 2) { if (args[

Re: Invoking the compiler during runtime

2020-08-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-08-05 09:57, cy wrote: Well, I did find this: https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ That is more for using the frontend, not the backend for generating code. But it's pretty advanced... probably just invoking dmd would be good... You can st

Non-recursive maxSizeOf

2020-08-05 Thread Per Nordlöw via Digitalmars-d-learn
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!(T[1 .. $]); enum size_t maxSizeOf = firstSize >= maxSi

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

2020-08-05 Thread Victor L Porton via Digitalmars-d-learn
When to use core.thread and when std.concurrency for multithreading in applications? Is one of them a preferred way?

Re: Non-recursive maxSizeOf

2020-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 00:58:39 UTC, Per Nordlöw wrote: Is it possible to implement in a non-recursive way? It is very easy too... just write an ordinary function: size_t maxSizeOf(T...)() { size_t max = 0; foreach(t; T) if(t.sizeof > max)

Re: Non-recursive maxSizeOf

2020-08-05 Thread Ali Çehreli via Digitalmars-d-learn
On 8/5/20 5:58 PM, 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!(T[1 .. $]);

Re: Non-recursive maxSizeOf

2020-08-05 Thread lithium iodate via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:13:41 UTC, Adam D. Ruppe wrote: size_t maxSizeOf(T...)() { size_t max = 0; foreach(t; T) if(t.sizeof > max) max = t.sizeof; return max; } pragma(msg, maxSizeOf!(int, char, long)); more love for pho

Re: Non-recursive maxSizeOf

2020-08-05 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: Non-recursive maxSizeOf

2020-08-05 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:13:41 UTC, Adam D. Ruppe wrote: It is very easy too... just write an ordinary function: size_t maxSizeOf(T...)() { size_t max = 0; foreach(t; T) if(t.sizeof > max) max = t.sizeof; return max; } prag

Re: Non-recursive maxSizeOf

2020-08-05 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:17:51 UTC, lithium iodate wrote: more love for phobos pls template maxSizeOf(T...) { template sizeOf(T) { // doesn't exist in phobos? enum sizeOf = T.sizeof; } enum size_t maxSizeOf = maxElement([staticMap!(sizeOf, T)]); } `std.meta.staticMa

Re: Non-recursive maxSizeOf

2020-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:17:51 UTC, lithium iodate wrote: more love for phobos pls That would add a lot to the cost and bring no real benefit

Re: Non-recursive maxSizeOf

2020-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:23:33 UTC, Per Nordlöw wrote: How does the memory usage and speed of this code compare to the variant that uses template instantiations? I haven't tested this specifically, but similar tests have come in at like 1/10th the memory and compile time cost. There