Re: template instantiation problems

2020-01-10 Thread ag0aep6g via Digitalmars-d-learn

On 10.01.20 18:27, berni44 wrote:
This clearly shows, that packageName is only instatiated once at top 
level although mod0 and mod1 are two different things (at least their 
stringof produces different results) and therefore should be 
instantiated twice.


Now I don't know if this is a bug in DMD or I should know something I do 
not know... Can you help me?



import m1 = foo.baz;
import m2 = foo;
alias p = __traits(parent, m1);

pragma(msg, m1.stringof); /* "module baz", ok */
pragma(msg, m2.stringof); /* "module foo", ok */
pragma(msg, p.stringof); /* "package foo", ok */

enum e(alias thing) = thing.stringof;

pragma(msg, e!m1); /* "module baz", ok */
pragma(msg, e!m2); /* "module foo", ok */
pragma(msg, e!p); /* "module foo", wat?? */


If you switch the last two lines around, you get "package foo" twice.

The compiler apparently thinks that m2 (module foo) and p (package foo) 
are the same thing when used as a template argument. So it reuses the 
previous result.


There's a similar issue with values:

https://issues.dlang.org/show_bug.cgi?id=14501


Re: Win32 Api: How create Open/"Save as" Dialog?

2020-01-10 Thread René Heldmaier via Digitalmars-d-learn

On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:
How create "Open" and "Save as" Dialog using "Win32 Api" and 
Dlang? Please send me a simple example code in Dlang. Thank you 
very much.


Have a look at this website: 
http://www.winprog.org/tutorial/app_two.html

It helped me a lot when i once made a simple gui in C.
The tutorial is in C, but Win32 Api is C anyway... Most of the 
examples will probably just compile in D.
Win32 Api is really ugly, i think it's a better investment to 
learn something like GtkD ;)


Re: Easiest way to use FMA instruction

2020-01-10 Thread kinke via Digitalmars-d-learn

On Friday, 10 January 2020 at 00:02:52 UTC, Johan wrote:

For LDC:
[...]


Simpler variant:

```
import ldc.intrinsics;
...
const result = llvm_fma(a, b, c);
```

This LLVM intrinsic is also used in LDC's Phobos for 
std.math.fma(); unfortunately, upstream Phobos just has a 
`real`-version, so the float/double versions aren't enabled yet: 
https://github.com/ldc-developers/phobos/blob/26d14c1a292267a32ce64fa7f219acc3d3cca274/std/math.d#L8370-L8376


Win32 Api: How create Open/"Save as" Dialog?

2020-01-10 Thread Marcone via Digitalmars-d-learn
How create "Open" and "Save as" Dialog using "Win32 Api" and 
Dlang? Please send me a simple example code in Dlang. Thank you 
very much.


Re: Win32 Api: How create Open/"Save as" Dialog?

2020-01-10 Thread Marcone via Digitalmars-d-learn

On Friday, 10 January 2020 at 14:52:36 UTC, Adam D. Ruppe wrote:

On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:
How create "Open" and "Save as" Dialog using "Win32 Api" and 
Dlang? Please send me a simple example code in Dlang. Thank 
you very much.


You just call GetOpenFileName or GetSaveFileName.

here it is in my minigui.d

https://github.com/adamdruppe/arsd/blob/master/minigui.d#L6634


Very complicated. Can you send me the simple clear code?


Re: Win32 Api: How create Open/"Save as" Dialog?

2020-01-10 Thread Mike Parker via Digitalmars-d-learn

On Friday, 10 January 2020 at 15:06:07 UTC, Marcone wrote:



Very complicated. Can you send me the simple clear code?


https://docs.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialog-boxes


Re: Win32 Api: How create Open/"Save as" Dialog?

2020-01-10 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 10 January 2020 at 14:48:49 UTC, Marcone wrote:
How create "Open" and "Save as" Dialog using "Win32 Api" and 
Dlang? Please send me a simple example code in Dlang. Thank you 
very much.


You just call GetOpenFileName or GetSaveFileName.

here it is in my minigui.d

https://github.com/adamdruppe/arsd/blob/master/minigui.d#L6634


template instantiation problems

2020-01-10 Thread berni44 via Digitalmars-d-learn
I'm trying to understand issue 17441 [1]. I reduced it (including 
Phobos) to the following (and added some message to point out the 
problem):


test.d:
---
alias parentOf(alias sym) = __traits(parent, sym);

template packageName(alias T)
{
pragma(msg, "IN: ", T.stringof);
static if (__traits(compiles, parentOf!T))
enum parent = packageName!(parentOf!T);
else
enum string parent = null;

static if (T.stringof[0..8] == "package ")
enum packageName = (parent? parent ~ '.' : "") ~ 
T.stringof[8 .. $];

else
enum packageName = parent;
}

void main()
{
import mod0 = foo.baz;
import mod1 = foo;

pragma(msg, "mod0: ",mod0.stringof);
pragma(msg, "mod1: ",mod1.stringof);

pragma(msg, "A");
enum a = packageName!mod0;
pragma(msg, "B");
enum b = packageName!mod1;
pragma(msg, "C");

static assert(a == "foo");
static assert(b == "");  // Error: static assert:  "foo" 
== "" is false

}
---

foo/baz.d:
---
module foo.baz;
---

foo/package.d:
---
module foo;
---

When compiling with

$> dmd test.d

I get:

---
mod0: module baz
mod1: module foo
A
IN: module baz
IN: package foo
B
C
test.d(32): Error: static assert:  "foo" == "" is false
---

This clearly shows, that packageName is only instatiated once at 
top level although mod0 and mod1 are two different things (at 
least their stringof produces different results) and therefore 
should be instantiated twice.


Now I don't know if this is a bug in DMD or I should know 
something I do not know... Can you help me?


[1] https://issues.dlang.org/show_bug.cgi?id=17441


Re: Win32 Api: How create a Color Dialog?

2020-01-10 Thread Marcone via Digitalmars-d-learn

On Thursday, 9 January 2020 at 21:55:26 UTC, Dennis wrote:

On Thursday, 9 January 2020 at 13:04:33 UTC, Marcone wrote:

[...]


Windows has the 'common dialog' module with a ChooseColor 
function you can use.


[...]


Very Good! Working very well!