Re: "if" is not evaluated for fields of Class.tupleof

2017-05-22 Thread Timoses via Digitalmars-d-learn
The easiest way is probably casting: ``` import std.traits; import std.bitmanip; class Test { byte[4] marray; byte mbyte; } void main() { auto value = [0x12, 0x23, 0x34, 0x45, 0x56]; auto test = cast(Test*) value.ptr; } ```

Re: [OT] #define

2017-05-22 Thread Andrew Edwards via Digitalmars-d-learn
On Monday, 22 May 2017 at 18:48:44 UTC, Adam D. Ruppe wrote: On Monday, 22 May 2017 at 18:44:10 UTC, Andrew Edwards wrote: Both happen to be the exact same. So does mean that for every function pointer in the file, I need to duplicate as such? You can use `extern(System)` or that case in D. I

Re: Mixin in Inline Assembly

2017-05-22 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 17:32:35 UTC, Era Scarecrow wrote: Still I think I'll impliment my own version and then if it's faster I'll submit it. Decided I'd give my hand at writing a 'ScaledInt' which is intended to basically allow any larger unsigned type. Coming across some assembl

Re: Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-22 Thread David Zhang via Digitalmars-d-learn
On Sunday, 21 May 2017 at 10:03:58 UTC, Nicholas Wilson wrote: As in the function signature of the function you call `ok` or `error` in. Result!(int, SomeEnum) myfunc(bool foo) { if(!foo) return ok(42); else return error(SomeEnum.fooHappened); } should work. This is w

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread evilrat via Digitalmars-d-learn
On Monday, 22 May 2017 at 18:51:43 UTC, ParticlePeter wrote: On Monday, 22 May 2017 at 14:01:56 UTC, Jerry wrote: IIRC the problem is that it isn't a POD type. ImVec2 has its own default constructor. The problem now is that because it no longer is POD, Window's ABI handles it different and doe

Re: trait detecting anonymous union?

2017-05-22 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 22 May 2017 at 21:03:42 UTC, Bastiaan Veelo wrote: Is there a way to detect at CT that S has overlapping data members, when an anonimous union is used as above? I have an implementation here: https://github.com/CyberShadow/rclidasm/blob/31bde3347ec1259026b6ab15e2305f2a99e63a30/src/r

Re: [OT] #define

2017-05-22 Thread Mike Parker via Digitalmars-d-learn
On Monday, 22 May 2017 at 18:44:10 UTC, Andrew Edwards wrote: There isn't any Windows specific section. Every function pointer in the library is decorated in one of the following two forms void (APIENTRY *NAME)(PARAMS) or void (APIENTRYP NAME)(PARAMS) Sorry, I worded that poorly.

Re: templatized delegate

2017-05-22 Thread Alex via Digitalmars-d-learn
On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: On 05/22/2017 11:04 AM, Alex wrote: [...] Not only is a template not an lvalue, it's not any kind of value at all. It doesn't have a type. You can't have a variable holding a template. You can't pass it as an argument. But a template

Re: trait detecting anonymous union?

2017-05-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 22 May 2017 at 21:03:42 UTC, Bastiaan Veelo wrote: ` void main() { import std.stdio; struct S { int i; union { int a; double b; } } S

Re: templatized delegate

2017-05-22 Thread ag0aep6g via Digitalmars-d-learn
On 05/22/2017 11:04 AM, Alex wrote: 3. Now the hard stuff comes. I want to templatize my delegate. struct A(alias dg) { auto fun(T, U...)(T t, U u) { return dg!(T, U)(t, u); } } struct C { A!dlgptr a; /* static? */ template dlgptr(T, U...) { /* st

Re: How to get rid of const / immutable poisoning (and I didn't even want to use them...)

2017-05-22 Thread ag0aep6g via Digitalmars-d-learn
On 05/22/2017 10:13 PM, Enjoys Math wrote: immutable struct String(T) { Marking a whole struct as `immutable` is usually a mistake. It applies to all methods, making them unusable on mutable and const instances. public: this(immutable T[] s) { This means you can create `String`s only

Re: templatized delegate

2017-05-22 Thread Alex via Digitalmars-d-learn
On Monday, 22 May 2017 at 20:38:27 UTC, Dukc wrote: On Monday, 22 May 2017 at 09:04:15 UTC, Alex wrote: 2. Now, I want to store the delegate in another struct. If I want to do this, I have to define the pointer as static. This is not intended at the beginning, but it's ok, as I know, that the

trait detecting anonymous union?

2017-05-22 Thread Bastiaan Veelo via Digitalmars-d-learn
` void main() { import std.stdio; struct S { int i; union { int a; double b; } } S s; writeln(s); // S(10, #{overlap a, b

Re: templatized delegate

2017-05-22 Thread Dukc via Digitalmars-d-learn
On Monday, 22 May 2017 at 09:04:15 UTC, Alex wrote: 2. Now, I want to store the delegate in another struct. If I want to do this, I have to define the pointer as static. This is not intended at the beginning, but it's ok, as I know, that the delegate would be the same across all instances of B.

Re: 'real' not able to store it's largest value

2017-05-22 Thread colin via Digitalmars-d-learn
D'oh! Thanks Adam and Ali :)

Re: 'real' not able to store it's largest value

2017-05-22 Thread Ali Çehreli via Digitalmars-d-learn
On 05/22/2017 01:26 PM, colin wrote: Am I doing something wrong here? real.max evaluates to: 1.18973e+4932 So, I'd expect to be able to store any value up to that... however ``` void main() { writeln("Real max: ", real.max); foreach(i; 0..10){ writefln!("1024 ^^ %s = %s")(i, rea

Re: 'real' not able to store it's largest value

2017-05-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 22 May 2017 at 20:26:27 UTC, colin wrote: writefln!("1024 ^^ %s = %s")(i, real(1024 ^^ i)); You convert to real AFTER doing the exponent on an integer. change `real(1024 ^^ i)` to `real(1024) ^^ i` and you should get a different result.

'real' not able to store it's largest value

2017-05-22 Thread colin via Digitalmars-d-learn
Am I doing something wrong here? real.max evaluates to: 1.18973e+4932 So, I'd expect to be able to store any value up to that... however ``` void main() { writeln("Real max: ", real.max); foreach(i; 0..10){ writefln!("1024 ^^ %s = %s")(i, real(1024 ^^ i)); } } ``` Output: ``

Re: How to get rid of const / immutable poisoning (and I didn't even want to use them...)

2017-05-22 Thread Enjoys Math via Digitalmars-d-learn
On Monday, 22 May 2017 at 20:12:56 UTC, Enjoys Math wrote: I had to employ const / immutable to some things to get passed some compiler errors. Then the poisoning continues. How do I get this code to run? String's will hold a T[] which actually will not be modified by the String methods ("im

Re: How to get rid of const / immutable poisoning (and I didn't even want to use them...)

2017-05-22 Thread Enjoys Math via Digitalmars-d-learn
On Monday, 22 May 2017 at 20:12:56 UTC, Enjoys Math wrote: I had to employ const / immutable to some things to get passed some compiler errors. Then the poisoning continues. How do I get this code to run? String's will hold a T[] which actually will not be modified by the String methods ("im

How to get rid of const / immutable poisoning (and I didn't even want to use them...)

2017-05-22 Thread Enjoys Math via Digitalmars-d-learn
I had to employ const / immutable to some things to get passed some compiler errors. Then the poisoning continues. How do I get this code to run? String's will hold a T[] which actually will not be modified by the String methods ("immutable strings of T"). I did not want to use any immutabl

Re: How do you call hashOf() on a string?

2017-05-22 Thread Enjoys Math via Digitalmars-d-learn
Changing @safe to @system worked. IDK, but w/e! ;-)

How do you call hashOf() on a string?

2017-05-22 Thread Enjoys Math via Digitalmars-d-learn
module smallest_grammar; import std.conv; import std.algorithm; struct Symbol(T) { public: this(T sym, bool isVar) { this.sym = sym; this.is_var = isVar; } @property T symbol() { return sym; } @property bool isVar() { return is_var

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread ParticlePeter via Digitalmars-d-learn
On Monday, 22 May 2017 at 14:01:56 UTC, Jerry wrote: IIRC the problem is that it isn't a POD type. ImVec2 has its own default constructor. The problem now is that because it no longer is POD, Window's ABI handles it different and doesn't put the value in a register. Now with D is that you aren

Re: [OT] #define

2017-05-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 22 May 2017 at 18:44:10 UTC, Andrew Edwards wrote: Both happen to be the exact same. So does mean that for every function pointer in the file, I need to duplicate as such? You can use `extern(System)` or that case in D. It will be extern(Windows) on win an extern(C) elsewhere - just

Re: [OT] #define

2017-05-22 Thread Andrew Edwards via Digitalmars-d-learn
On Monday, 22 May 2017 at 16:56:10 UTC, Mike Parker wrote: On Monday, 22 May 2017 at 16:37:51 UTC, Andrew Edwards wrote: Specific context at the following links: https://github.com/glfw/glfw/blob/66ff4aae89572419bb130c5613798e34d7521fc7/deps/glad/glad.h#L24-L48 Generally, any functions in

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread ParticlePeter via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:03:17 UTC, evilrat wrote: On Monday, 22 May 2017 at 11:25:31 UTC, ParticlePeter wrote: Then I am not getting your hack, this function here, does not exist on the C++ side. HACK --- // extern(C++) of course void GetCursorPos(ImVec2* v); Ho

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread Mike Parker via Digitalmars-d-learn
On Monday, 22 May 2017 at 14:11:35 UTC, Jerry wrote: are you aware of https://github.com/Extrawurst/DerelictImgui ? Not everyone likes the set of 'derelict' libraries. Especially if you need to statically link to a library. Some of the Derelict packages in the DerelictOrg repo (the SDL2, G

Re: [OT] #define

2017-05-22 Thread Mike Parker via Digitalmars-d-learn
On Monday, 22 May 2017 at 16:37:51 UTC, Andrew Edwards wrote: Specific context at the following links: https://github.com/glfw/glfw/blob/66ff4aae89572419bb130c5613798e34d7521fc7/deps/glad/glad.h#L24-L48 APIENTRY is typically defined in Windows headers to set the stdcall calling convention

Re: [OT] #define

2017-05-22 Thread Andrew Edwards via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:52:35 UTC, Dukc wrote: On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: Sorry if this is a stupid question but it eludes me. In the following, what is THING? What is SOME_THING? [...] I assume you know that the above part is c/c++ preprocessor, which

Re: [OT] #define

2017-05-22 Thread Andrew Edwards via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:15:31 UTC, Adam D. Ruppe wrote: On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: #ifndef THING #define THING #endif This kind of thing is most commonly used in include guards https://en.wikipedia.org/wiki/Include_guard#Use_of_.23include_gu

Re: [OT] #define

2017-05-22 Thread Andrew Edwards via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:18:51 UTC, Eugene Wissner wrote: On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: Sorry if this is a stupid question but it eludes me. In the following, what is THING? What is SOME_THING? #ifndef THING #define THING #endif #ifndef SOME

Re: Getting DUB to work with VS 2017

2017-05-22 Thread Enjoys Math via Digitalmars-d-learn
On Monday, 22 May 2017 at 06:44:27 UTC, Rainer Schuetze wrote: On 22.05.2017 03:54, Enjoys Math wrote: [...] C:\Users\Gabe\AppData\Roaming\dub\packages\pyd-0.9.9\pyd\\infrastructure\windows\python27_digitalmars.lib+ user32.lib+ kernel32.lib/NOMAP/CO/NOI/DELEXE LINK : fatal error LNK1181: cann

Re: Which editor to use for editing DDOCs?

2017-05-22 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2017-05-22 at 14:14 +, biocyberman via Digitalmars-d-learn wrote: > Which one do you use? I am using Linux and Emacs for editing > other D source file. But the DDOC syntaxes and keywords are not > well high-lighted. There has been no work on handling DDOC comments specially in the Em

Which editor to use for editing DDOCs?

2017-05-22 Thread biocyberman via Digitalmars-d-learn
Which one do you use? I am using Linux and Emacs for editing other D source file. But the DDOC syntaxes and keywords are not well high-lighted.

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread Jerry via Digitalmars-d-learn
On Sunday, 21 May 2017 at 19:58:32 UTC, Stefan Koch wrote: On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote: I am statically linking to ImGui [1] on Win 10 x64, quite successfully till this issue came up. The noticed error so far comes when an ImGui function returns an ImVec2, a simp

Re: [OT] #define

2017-05-22 Thread biocyberman via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: Sorry if this is a stupid question but it eludes me. In the following, what is THING? What is SOME_THING? #ifndef THING #define THING #endif #ifndef SOME_THING #define SOME_THING THING * #endif Is this equiv

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread Jerry via Digitalmars-d-learn
Note that you also probably need extern(C++) on the struct ImVec2. https://github.com/ParticlePeter/imgui_lib/blob/master/source/imgui/types.d#L84

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread Jerry via Digitalmars-d-learn
On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote: I am statically linking to ImGui [1] on Win 10 x64, quite successfully till this issue came up. The noticed error so far comes when an ImGui function returns an ImVec2, a simple POD struct of two float members. I can use this struct a

Re: [OT] #define

2017-05-22 Thread Dukc via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: Sorry if this is a stupid question but it eludes me. In the following, what is THING? What is SOME_THING? #ifndef THING #define THING #endif #ifndef SOME_THING #define SOME_THING THING * #endif Is this equiv

Re: [OT] #define

2017-05-22 Thread Eugene Wissner via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: Sorry if this is a stupid question but it eludes me. In the following, what is THING? What is SOME_THING? #ifndef THING #define THING #endif #ifndef SOME_THING #define SOME_THING THING * #endif Is this equiv

Re: [OT] #define

2017-05-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: #ifndef THING #define THING #endif This kind of thing is most commonly used in include guards https://en.wikipedia.org/wiki/Include_guard#Use_of_.23include_guards You can usually just strip that out in D, since the modu

[OT] #define

2017-05-22 Thread Andrew Edwards via Digitalmars-d-learn
Sorry if this is a stupid question but it eludes me. In the following, what is THING? What is SOME_THING? #ifndef THING #define THING #endif #ifndef SOME_THING #define SOME_THING THING * #endif Is this equivalent to: alias thing = void; alias someThing = thing*

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread evilrat via Digitalmars-d-learn
On Monday, 22 May 2017 at 11:25:31 UTC, ParticlePeter wrote: Then I am not getting your hack, this function here, does not exist on the C++ side. HACK --- // extern(C++) of course void GetCursorPos(ImVec2* v); How is it supposed to work then if there is no definition?

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread ParticlePeter via Digitalmars-d-learn
On Monday, 22 May 2017 at 08:25:45 UTC, evilrat wrote: On Monday, 22 May 2017 at 08:03:07 UTC, ParticlePeter wrote: No, no, this (other) way around :-), still C++ to D. It actually works btw: HACK --- // original C++ ImVec2 GetCursorPos(); // C++ helper void GetCurs

Re: Code improvement for DNA reverse complement?

2017-05-22 Thread biocyberman via Digitalmars-d-learn
On Monday, 22 May 2017 at 10:35:36 UTC, ag0aep6g wrote: On 05/22/2017 10:58 AM, biocyberman wrote: [...] For reference, here is the version of revComp3 I commented on: string revComp3(string bps) { const N = bps.length; enum chars = [Repeat!('A'-'\0', '\0'), 'T',

Re: how to disable inlining of ldc2 when 'dub build --build=release'?

2017-05-22 Thread lixiaozi via Digitalmars-d-learn
On Saturday, 20 May 2017 at 10:22:14 UTC, Stanislav Blinov wrote: On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote: so, what should i do to disable inlining of ldc2 in release build? As Stefan mentioned, a test case would be nice. But have you tried annotating the offending function

Re: how to disable inlining of ldc2 when 'dub build --build=release'?

2017-05-22 Thread lixiaozi via Digitalmars-d-learn
On Saturday, 20 May 2017 at 08:22:43 UTC, Stefan Koch wrote: On Saturday, 20 May 2017 at 08:08:38 UTC, Johan Engelen wrote: On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote: [...] I noticed it's the inline optimization in ldc2 that caused the crash. If you are certain that your code

Re: Code improvement for DNA reverse complement?

2017-05-22 Thread ag0aep6g via Digitalmars-d-learn
On 05/22/2017 10:58 AM, biocyberman wrote: @ag0aep6g You fell into a trap there. The value is calculated at compile time, but it has >copy/paste-like behavior. That is, whenever you use `chars`, the code behaves as if you >typed out the array literal. That means, the whole array is re-created

Re: how to disable inlining of ldc2 when 'dub build --build=release'?

2017-05-22 Thread lixiaozi via Digitalmars-d-learn
On Saturday, 20 May 2017 at 08:08:38 UTC, Johan Engelen wrote: On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote: [...] I noticed it's the inline optimization in ldc2 that caused the crash. If you are certain that your code is 100% correct, please file a bug report. Inlining is done b

Re: Code improvement for DNA reverse complement?

2017-05-22 Thread Biotronic via Digitalmars-d-learn
On Monday, 22 May 2017 at 08:58:24 UTC, biocyberman wrote: @Nicolas Wilson: Your explanation of the enum is clear and very helpful. I can recall to the same technique used in kh_hash in samtools and the associated. With that said, the chars enum is only to 'T' (85) elements. The reason for ha

Re: how to disable inlining of ldc2 when 'dub build --build=release'?

2017-05-22 Thread lixiaozi via Digitalmars-d-learn
On Saturday, 20 May 2017 at 08:11:06 UTC, Johan Engelen wrote: On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote: Now, I try to disable inlining in "dub.json" like == "dflags":[ "-disable-inlining" ], == but it doesn't work, because then dub calls ldc2 like this:

templatized delegate

2017-05-22 Thread Alex via Digitalmars-d-learn
Hi, all I have a question, how to handle a templated delegate. However, I'm not sure, if I'm going in the right direction, so I have three examples, and my question is about the third. 1. Here, a struct with an alias is defined and on its creation the delegate get known to the struct. Everyth

Re: Code improvement for DNA reverse complement?

2017-05-22 Thread biocyberman via Digitalmars-d-learn
On Monday, 22 May 2017 at 06:50:45 UTC, Biotronic wrote: On Friday, 19 May 2017 at 22:53:39 UTC, crimaniak wrote: On Friday, 19 May 2017 at 12:55:05 UTC, Biotronic wrote: revComp6 seems to be the fastest, but it's probably also the least readable (a common trade-off). Try revComp7 with -releas

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread evilrat via Digitalmars-d-learn
On Monday, 22 May 2017 at 08:03:07 UTC, ParticlePeter wrote: No, no, this (other) way around :-), still C++ to D. It actually works btw: HACK --- // original C++ ImVec2 GetCursorPos(); // C++ helper void GetCursorPos(ImVec2& result) { result = GetCursorPos(); } //

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread ParticlePeter via Digitalmars-d-learn
On Monday, 22 May 2017 at 07:24:20 UTC, evilrat wrote: On Monday, 22 May 2017 at 06:33:37 UTC, ParticlePeter wrote: On Monday, 22 May 2017 at 01:39:04 UTC, evilrat wrote: And this is actually D problem. In fact first bug report on this thing was dated back to 2014. Still not fixed. Thanks

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread evilrat via Digitalmars-d-learn
On Monday, 22 May 2017 at 06:33:37 UTC, ParticlePeter wrote: On Monday, 22 May 2017 at 01:39:04 UTC, evilrat wrote: And this is actually D problem. In fact first bug report on this thing was dated back to 2014. Still not fixed. Thanks for your reply, do you have any links to some bug report