zip with fieldTuple

2014-06-06 Thread John via Digitalmars-d-learn
So let's say I'm trying to create a really simple ORM. I have a struct: struct foo { int a; float b; } I can iterate over the struct elements with the traits FieldTypeTuple!foo, I can iterate over the the string that represents the elements I want to shove in the struct, but

Re: zip with fieldTuple

2014-06-06 Thread John via Digitalmars-d-learn
On Friday, 6 June 2014 at 22:27:38 UTC, bearophile wrote: John: I can iterate over the struct elements with the traits FieldTypeTuple!foo, In such iteration you are using a static foreach. Types are compile-time constructs in D. If you need run-time entities you need to get their typeinfo.

How can I use AVX instructions in D inline asm?

2014-09-11 Thread John via Digitalmars-d-learn
Hi. Now I try to use SSE/AVX instructions in D inline asm. I have a trouble about this. In http://dlang.org/iasm.html , AVX seems to be supported according to SIMD section in the paeg. But there is no AVX opcodes, like vaddps, in Opcodes section in the page. So I have assumed addps can be

Need assistance translating this C++ template

2014-10-27 Thread John via Digitalmars-d-learn
Howdy, I stumbled across a tiny NES emulator written in C++ (http://bisqwit.iki.fi/jutut/kuvat/programming_examples/nesemu1/nesemu1.cc) that I feel compelled to make even tinier with some D magic. I am having trouble with a nested template in the code. The C++ code: // Bitfield utilities

Re: Need assistance translating this C++ template

2014-10-27 Thread John via Digitalmars-d-learn
On Monday, 27 October 2014 at 23:19:42 UTC, anonymous wrote: On Monday, 27 October 2014 at 22:43:23 UTC, John wrote: The C++ code: // Bitfield utilities templateunsigned bitno, unsigned nbits=1, typename T=u8 struct RegBit { [...] templatetypename T2 RegBit operator=(T2 val) [...] };

Using arrays of function pointers in D

2015-05-21 Thread John via Digitalmars-d-learn
I've been rewriting one of my emulators in D and am fairly new to the language. I'm having trouble finding documentation on creating/initializing/use of arrays of function pointers in D. If anyone has a code example I'd appreciate it!

Re: Using arrays of function pointers in D

2015-05-21 Thread John via Digitalmars-d-learn
On Thursday, 21 May 2015 at 16:25:24 UTC, Adam D. Ruppe wrote: Start with a function type declaration: void function() func_ptr; Then make an array out of it: void function()[] func_ptr_array; It works like other arrays, just the [] might be a little harder to see since it is a much longer

Calling D Code from Assembly

2015-07-11 Thread John via Digitalmars-d-learn
Is there a way I can call D code from assembly without declaring functions as extern(C) and and doing it the C way?

Re: Calling D Code from Assembly

2015-07-11 Thread John via Digitalmars-d-learn
On Sunday, 12 July 2015 at 04:30:58 UTC, John wrote: Is there a way I can call D code from assembly without declaring functions as extern(C) and and doing it the C way? SOLVED: Found the calling convention description. http://dlang.org/abi.html

Re: @property not available for classes?

2016-01-01 Thread John via Digitalmars-d-learn
On Friday, 1 January 2016 at 10:14:58 UTC, Shriramana Sharma wrote: Hello. I'm trying the following code: import std.stdio; class TimeSpan { immutable double start, end; @property double length() { return end - start; } } void main() { auto p = TimeSpan(1, 2); writeln(p.length);

Re: Implicit conversion of struct to bool for if (s) operation ?

2016-06-06 Thread John via Digitalmars-d-learn
On Monday, 6 June 2016 at 15:23:50 UTC, chmike wrote: Hello, I have a structure with two fields ad defined as struct Info { this(int value, Category category) { category_ = category; value_ = category ? value : 0; } // This converts implicitly to bool.

Re: Accessing COM Objects

2016-06-13 Thread John via Digitalmars-d-learn
On Monday, 13 June 2016 at 01:22:33 UTC, Incognito wrote: I've been reading over D's com and can't find anything useful. It seems there are different ways: http://www.lunesu.com/uploads/ModernCOMProgramminginD.pdf which is of no help and requires an idl file, which I don't have. Then

Re: Accessing COM Objects

2016-06-14 Thread John via Digitalmars-d-learn
On Monday, 13 June 2016 at 19:26:08 UTC, Incognito wrote: On Monday, 13 June 2016 at 19:11:59 UTC, John wrote: On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote: Cool. Oleview gives me the idl files. How to convert the idl files to d or possibly c? Would I just use them in place of

Re: Accessing COM Objects

2016-06-15 Thread John via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:21:06 UTC, John wrote: OK, adding the return type to the signature should fix that. So: private static Parameter getParameters(MethodImpl method) Sorry, I meant the getParameter methods should return be: private static Parameter[] getParameters(MethodImpl

Re: Accessing COM Objects

2016-06-15 Thread John via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 06:56:59 UTC, Joerg Joergonson wrote: When I try to compile your code I get the following errors: main.d(953): Error: function core.sys.windows.objbase.CoTaskMemAlloc (uint) is not callable using argument types (immutable(ulong)) main.d(970): Error: can only

Re: Accessing COM Objects

2016-06-15 Thread John via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 16:45:39 UTC, Joerg Joergonson wrote: Thanks. When I ran it I got a d file! when I tried to use that d file I get undefined IID and IDispatch. I imagine these interfaces come from somewhere, probably built in? Any ideas? Add the following after the module name:

Re: Accessing COM Objects

2016-06-13 Thread John via Digitalmars-d-learn
On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote: Cool. Oleview gives me the idl files. How to convert the idl files to d or possibly c? Would I just use them in place of IUnknown once I have the interface? In OleView you can save the IDL file, then run another tool, midl.exe, on

Re: Request assistance binding to Windows dsound.{lib, dll}

2016-05-27 Thread John via Digitalmars-d-learn
Additionally, remove QueryInterface, AddRef and Release from the definition of IDirectSound. Also, interfaces are already references, so the definition of LPDIRECTSOUND should be: alias LPDIRECTSOUND = IDirectSound; Note there should be no *. Regarding any linking errors, it's easier to

Re: Accessing COM Objects

2016-06-15 Thread John via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 18:35:42 UTC, Joerg Joergonson wrote: On Wednesday, 15 June 2016 at 06:09:33 UTC, thedeemon wrote: On Monday, 13 June 2016 at 17:38:41 UTC, Incognito wrote: [...] There are ready tools idl2d: https://github.com/dlang/visuald/tree/master/c2d [...] I can't

Re: Accessing COM Objects

2016-06-15 Thread John via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 18:32:28 UTC, Joerg Joergonson wrote: import core.sys.windows.com, core.sys.windows.oaidl; Thanks. Should these not be added to the generated file? The problem is that other type libraries will probably require other headers to be imported, and there's no way

Re: Getting the template name of a template instantiation

2016-06-27 Thread John via Digitalmars-d-learn
On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote: If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?

Re: Getting the template name of a template instantiation

2016-06-27 Thread John via Digitalmars-d-learn
On Monday, 27 June 2016 at 17:14:23 UTC, John wrote: On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote: If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static

Re: Registration-free COM client

2016-06-28 Thread John via Digitalmars-d-learn
On Monday, 27 June 2016 at 21:17:52 UTC, Thalamus wrote: Hi everyone, I've succeeded in using D as a client for regular (registered) COM servers in the past, but in this case, I'm building the server as well. I would like to avoid registering it if possible so XCOPY-like deployment remains

static switch/pattern matching

2016-06-25 Thread John via Digitalmars-d-learn
Writing a long series of "static if ... else" statements can be tedious and I'm prone to leaving out the crucial "static" after "else", so I was wondered if it was possible to write a template that would resemble the switch statement, but for types. Closest I came up to was this: void

Re: static switch/pattern matching

2016-06-25 Thread John via Digitalmars-d-learn
On Saturday, 25 June 2016 at 09:12:12 UTC, Lodovico Giaretta wrote: On Saturday, 25 June 2016 at 09:07:19 UTC, Lodovico Giaretta wrote: Instead of passing functions to match!, pass pairs of arguments, like this: match!(T, int, writeln("Matched int"), is(T : SomeObject),

Re: Does D has any support for thunks?

2016-06-25 Thread John via Digitalmars-d-learn
On Saturday, 25 June 2016 at 13:44:48 UTC, Andre Pany wrote: Hi everyone, I have some issue with win32 function SetWindowsHookEx. For this specific funtion there is no possibility to pass extra data (pointer to a class instance to be called) to the callback function. The general solution

Re: static switch/pattern matching

2016-06-25 Thread John via Digitalmars-d-learn
On Saturday, 25 June 2016 at 12:35:39 UTC, Lodovico Giaretta wrote: On Saturday, 25 June 2016 at 12:30:22 UTC, Lodovico Giaretta wrote: If you want this to work, you need your lambdas to take the casted value as a parameter: Thanks.

Re: Accessing COM Objects

2016-06-17 Thread John via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 21:06:01 UTC, Joerg Joergonson wrote: My thinking is that CoCreateinstance is suppose to give us a pointer to the interface so we can use it, if all this stuff is crashing does that mean the interface is invalid or not being assigned properly or is there far more

Re: Trying to build a Scheme interpreter in D

2016-03-10 Thread John via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 20:30:44 UTC, Guillaume Piolat wrote: On Tuesday, 8 March 2016 at 18:11:24 UTC, John wrote: You can go with Algebraic. I used to do that in scheme-d. Then I switched to a tagged union by hand to avoid a compiler regression. Algebraic was OK. 2x speed

Specialized template in different module

2016-03-14 Thread John via Digitalmars-d-learn
If I define a template in one module, and specialize it in a second module, the compiler doesn't like it when I try to call a function using the template. module one; struct Test(T) {} void testing(T)(Test!T t) {} module two; struct Test(T : int) {} void main() { Test!int

Trying to build a Scheme interpreter in D

2016-03-08 Thread John via Digitalmars-d-learn
Hi, I'm currently reading "Programming in D" and in order to get accustomed to D and it's syntax, I've decided to implement (actually port) a simple (and naive) Scheme interpreter from C to D. The original interpreter (in C) is described in a series of posts here:

Re: Create Windows "shortcut" (.lnk) with D?

2016-03-06 Thread John via Digitalmars-d-learn
On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote: IShellLinkA* shellLink; IPersistFile* linkFile; Any help would be highly appreciated as I'm new to Windows programming in D and have no idea what I'm doing wrong! In D, interfaces are references, so it should be: IShellLinkA

Re: Dealing with unicode

2016-07-29 Thread John via Digitalmars-d-learn
On Friday, 29 July 2016 at 06:32:24 UTC, Fabian wrote: I'm trying to add support for unicode to my app in D and having issues. string str = "Pokémon No"; writeln(str); this outputs: Pok├®mon No what I want to do is change the funky character such that the string reads: Pok\u00e9mon No as

Re: C++ interface vs D and com

2016-07-13 Thread John via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 20:28:40 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 19:22:44 UTC, Kagamin wrote: On Wednesday, 13 July 2016 at 16:48:53 UTC, Adam Sansier wrote: There's a lot of misinformation on the net. Nope, it's just you. COM support in D and in general works

Re: C++ interface vs D and com

2016-07-13 Thread John via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 07:31:57 UTC, Adam Sansier wrote: void** ptr = null; auto res = CoCreateInstance(_ID, cast(IUnknown)null, CLSCTX_INPROC_SERVER, _ID, cast(void**)); How are you casting your "ptr" variable (which BTW should be just void* or usually IUnknown) to your

Re: Convert delegate or function type to other.

2016-07-18 Thread John via Digitalmars-d-learn
On Monday, 18 July 2016 at 18:49:22 UTC, Rufus Smith wrote: Suppose I have the following: alias func = void function(int); Is there a way to convert it automatically to something the same type except of delegate: alias del = toDel(func) = void delegate(int);? import std.traits; alias del =

Re: Passing a single tuple or multiple values

2016-07-19 Thread John via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 01:22:01 UTC, jmh530 wrote: import std.typecons : isTuple, tuple; import std.stdio : writeln; auto foo(T...)(T x) { T[0] y; foreach (i, e; x) { y += e; } return y; } auto bar(T)(T x) { static if

Re: counting characters

2016-07-19 Thread John via Digitalmars-d-learn
On Tuesday, 19 July 2016 at 09:34:11 UTC, celavek wrote: Hi, I am trying to count characters in a string like: const string dna_chain = "AGCCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAGAGTGTCTGATAGCAGC"; counts['A'] = countchars!(dna_chain, 'A'); countchars(dna_chain, "A");

Re: adding toString to struct

2016-07-12 Thread John via Digitalmars-d-learn
On Tuesday, 12 July 2016 at 14:51:43 UTC, Adam Sansier wrote: On Tuesday, 12 July 2016 at 14:27:49 UTC, Adam D. Ruppe wrote: On Tuesday, 12 July 2016 at 05:16:30 UTC, Adam Sansier wrote: Is there a way to do this? write a new function that prints them and call that This doesn't work to

Re: How to get current time as long or ulong?

2016-07-05 Thread John via Digitalmars-d-learn
On Tuesday, 5 July 2016 at 18:16:31 UTC, Charles Hixson wrote: I've been reading std.datetime documentation backwards and forwards, but if the information is there, I've been missing it. How do I get the current time as a long? Clock.currTime() returns a SysTime, and while currently I can

Re: Registration-free COM client

2016-06-29 Thread John via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 14:51:10 UTC, Thalamus wrote: and the D code (mostly unchanged from your example): interface ITestInterface { int Identifier(); } ITestInterface needs to derive from IUnknown.

Re: Registration-free COM client

2016-06-29 Thread John via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 17:55:27 UTC, John wrote: On Wednesday, 29 June 2016 at 14:51:10 UTC, Thalamus wrote: and the D code (mostly unchanged from your example): interface ITestInterface { int Identifier(); } ITestInterface needs to derive from IUnknown. I realise that doesn't

Re: Registration-free COM client

2016-06-29 Thread John via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 14:51:10 UTC, Thalamus wrote: I was hoping there would be a code-only solution, and I'm glad to see one is possible. It isn't quite working for me yet, though. I can get the HINSTANCE in the CoLoadLibrary call, but GetProcAddress for DllGetClassObject fails, with

Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible

2017-12-17 Thread John via Digitalmars-d-learn
On Sunday, 17 December 2017 at 15:57:08 UTC, ParticlePeter wrote: I upgraded from DMD 2.074.1 (!) to 2.077.1 and tried to compile a mixed c++/d project (DMD links to one c++ lib). Here is the full error message: fatal error C1905: Front end and back end not compatible (must target same

Re: Linker error since upgrade to DMD 2.077.1: fatal error C1905: Front end and back end not compatible

2017-12-17 Thread John via Digitalmars-d-learn
On Sunday, 17 December 2017 at 17:15:57 UTC, ParticlePeter wrote: On Sunday, 17 December 2017 at 16:40:46 UTC, John wrote: Yah the sc.ini file is wrong for Environment64. [Environment64] LIB="%@P%\..\lib64" . . . ; Windows installer uncomments the version detected

Re: Handling big FP numbers

2019-02-08 Thread John via Digitalmars-d-learn
On Saturday, 9 February 2019 at 02:12:29 UTC, Murilo wrote: Why is it that in C when I attribute the number 991234307654329925.7865 to a double it prints 991234299470108672. and in D it prints 9912342990. ? Apparently both languages cause a certain loss