Re: templatized delegate
On Tuesday, 23 May 2017 at 16:38:14 UTC, Stanislav Blinov wrote: Ah, now I think I get it. You want to store a single delegate that could be called with different sets of arguments? No, you can't do that: you need an actual delegate instance, and for that, you need to know the signature, at least when instantiating C. Yes :) or, just to differentiate between the used and unused parameters, without loosing their types and attributes. But that's a minor problem, the solution with full signature https://forum.dlang.org/post/ekbpjsuyqprusyasm...@forum.dlang.org#post-svvgcrymplmyondhuogt:40forum.dlang.org works also well, as the effort to name everything is not so big in my case...
Re: templatized delegate
On Tuesday, 23 May 2017 at 18:14:34 UTC, ag0aep6g wrote: Something like this: import core.vararg; import std.meta: AliasSeq, staticMap; import std.traits: isCopyable; struct A { void delegate(...) dg; auto fun(T, U ...)(T t, auto ref U u) { template UncopyableToPointer(T) { static if (!isCopyable!T) alias UncopyableToPointer = T*; else alias UncopyableToPointer = T; } alias U2 = staticMap!(UncopyableToPointer, U); U2 u2; foreach (i, E; U) { static if (!isCopyable!E) u2[i] = &u[i]; else u2[i] = u[i]; } return dg(t, u2); } } struct SomeStructThatIsNotCopyable { @disable this(this); } void main() { void dlg(...) { import std.stdio; foreach (i, t; _arguments) { foreach (T; AliasSeq!(int, string, SomeStructThatIsNotCopyable*)) { if (t == typeid(T)) { static if (is(T : U*, U) && !isCopyable!U) { write("uncopyable type"); } else write(_argptr.va_arg!T); } } /* otherwise: don't know how to handle the type */ write(" "); } writeln(); } auto a = A(&dlg); SomeStructThatIsNotCopyable s; a.fun(5, "a", /* by ref: */ s, /* or by pointer: */ &s); } That's not exactly pretty, of course. Both A.fun and the delegate are quite complicated. But it might be workable, if run-time variadics are acceptable. I wouldn't be surprised if the problem can be solved more elegantly. But I don't see how at the moment. That's cool :) but anyway, even if I have such params, there are not much of them, so it just a minor semantic issue to explicitely name them and their types instead of showing, that they are passed but not used inside dlg. And thanks a lot to all for great ideas :)
Re: templatized delegate
On 05/23/2017 01:30 PM, Alex wrote: And no, I can't pass it by adress, as I don't know apriori, whether the very parameter which gets the random generator is already a part of the variadic parameters, or a well defined ref parameter. A (run-time) variadic delegate isn't flexible like that. When you have a `void delegate(...)`, then there are no non-variadic parameters. You know both in the caller and in the callee that passing by ref is not an option. So you can define that uncopyable types are passed by pointer. Going this route means you have to make all your delegates variadic (this might be annoying). A.fun can remain a variadic template. It can also have ref parameters, but then you have to detect uncopyable types and pass pointers to the delegate. Something like this: import core.vararg; import std.meta: AliasSeq, staticMap; import std.traits: isCopyable; struct A { void delegate(...) dg; auto fun(T, U ...)(T t, auto ref U u) { template UncopyableToPointer(T) { static if (!isCopyable!T) alias UncopyableToPointer = T*; else alias UncopyableToPointer = T; } alias U2 = staticMap!(UncopyableToPointer, U); U2 u2; foreach (i, E; U) { static if (!isCopyable!E) u2[i] = &u[i]; else u2[i] = u[i]; } return dg(t, u2); } } struct SomeStructThatIsNotCopyable { @disable this(this); } void main() { void dlg(...) { import std.stdio; foreach (i, t; _arguments) { foreach (T; AliasSeq!(int, string, SomeStructThatIsNotCopyable*)) { if (t == typeid(T)) { static if (is(T : U*, U) && !isCopyable!U) { write("uncopyable type"); } else write(_argptr.va_arg!T); } } /* otherwise: don't know how to handle the type */ write(" "); } writeln(); } auto a = A(&dlg); SomeStructThatIsNotCopyable s; a.fun(5, "a", /* by ref: */ s, /* or by pointer: */ &s); } That's not exactly pretty, of course. Both A.fun and the delegate are quite complicated. But it might be workable, if run-time variadics are acceptable. I wouldn't be surprised if the problem can be solved more elegantly. But I don't see how at the moment.
Re: Structure of Arrays vs Array of Structures
On Tuesday, 23 May 2017 at 16:48:31 UTC, Nordlöw wrote: On Tuesday, 23 May 2017 at 16:46:18 UTC, Nordlöw wrote: http://forum.dlang.org/post/wvulryummkqtskiwr...@forum.dlang.org Correction; should be: https://github.com/nordlow/phobos-next/blob/a324f16515bd1c3c1185ba0482dae2886d811bb1/src/soa.d What if you instantiate it with a nested struct? What about structs that themselves aggregate other structs? What about custom operators on such structs?.. As I said earlier, generic solution is not easy. The implementation you have is very niche, certainly not "std.".
Re: Structure of Arrays vs Array of Structures
On Monday, 15 May 2017 at 19:52:03 UTC, Nordlöw wrote: soa.d-mixin-143(143,7): Error: variable soa.SOA!(S).SOA.container0LU cannot be further field because it will change the determined SOA size soa.d-mixin-143(143,28): Error: variable soa.SOA!(S).SOA.container1LU cannot be further field because it will change the determined SOA size soa.d(193,14): Error: template instance soa.SOA!(S) error instantiating soa.d(195,5): Error: static assert (is(typeof((__error)()) == int[])) is false What's wrong? When I removed the scope qualifier I went forward with `opDispatch` to make it work here http://forum.dlang.org/post/wvulryummkqtskiwr...@forum.dlang.org What about adding this little D-magic to std.typecons?
Re: Structure of Arrays vs Array of Structures
On Tuesday, 23 May 2017 at 16:46:18 UTC, Nordlöw wrote: http://forum.dlang.org/post/wvulryummkqtskiwr...@forum.dlang.org Correction; should be: https://github.com/nordlow/phobos-next/blob/a324f16515bd1c3c1185ba0482dae2886d811bb1/src/soa.d
Re: templatized delegate
On Tuesday, 23 May 2017 at 11:45:13 UTC, Alex wrote: On Tuesday, 23 May 2017 at 11:05:09 UTC, Stanislav Blinov wrote: void variadic(Args...)(auto ref Args args) { /* ... */ } This infers whether you pass lvalues or rvalues. If passing further down the chain of such calls is needed, one can use std.functional : fowrard : yes... void variadic(Args...)(auto ref Args args) { import std.functional : forward; doStuff(forward!args); } void doStuff(Args...)(auto ref Args args) { /* ... */ } 'forward' aliases ref arguments (i.e. passed lvalues) and moves value arguments (i.e. passed rvalues). If a value is not copyable, it may be move-able (check the docs though, it may not be that either). void fun(Args...)(auto ref Args args) { /*...*/ } yes... import std.algorithm : move; auto a = NonCopyable(42); fun(move(a)); // or: func(NonCopyable(42)); the problem, that I have is, that I would like to use the templated approach, but I don't have the function, but only a delegate, so: template(T, U...) { void delegate(ref T neededInput, ref U ignoredInput) dgPtr; } Not sure, if this is possible to handle at all... Ah, now I think I get it. You want to store a single delegate that could be called with different sets of arguments? No, you can't do that: you need an actual delegate instance, and for that, you need to know the signature, at least when instantiating C.
Re: How to get rid of const / immutable poisoning (and I didn't even want to use them...)
https://dpaste.dzfl.pl/74d67cfca3e8
Re: Which editor to use for editing DDOCs?
On Tuesday, 23 May 2017 at 07:40:21 UTC, biocyberman wrote: Adding DDOC support for D Mode require some more work obviously. I will see if I can make some changes to that. For the time being, I would like to know which editors people are using. Or is it a plain black and white editor ? I use Emacs and Geany.
Re: Which editor to use for editing DDOCs?
On Tuesday, 23 May 2017 at 07:40:21 UTC, biocyberman wrote: On Monday, 22 May 2017 at 15:33:36 UTC, Russel Winder wrote: [...] Adding DDOC support for D Mode require some more work obviously. I will see if I can make some changes to that. For the time being, I would like to know which editors people are using. Or is it a plain black and white editor ? I just use Atom.
Re: templatized delegate
On Tuesday, 23 May 2017 at 11:05:09 UTC, Stanislav Blinov wrote: void variadic(Args...)(auto ref Args args) { /* ... */ } This infers whether you pass lvalues or rvalues. If passing further down the chain of such calls is needed, one can use std.functional : fowrard : yes... void variadic(Args...)(auto ref Args args) { import std.functional : forward; doStuff(forward!args); } void doStuff(Args...)(auto ref Args args) { /* ... */ } 'forward' aliases ref arguments (i.e. passed lvalues) and moves value arguments (i.e. passed rvalues). If a value is not copyable, it may be move-able (check the docs though, it may not be that either). void fun(Args...)(auto ref Args args) { /*...*/ } yes... import std.algorithm : move; auto a = NonCopyable(42); fun(move(a)); // or: func(NonCopyable(42)); the problem, that I have is, that I would like to use the templated approach, but I don't have the function, but only a delegate, so: template(T, U...) { void delegate(ref T neededInput, ref U ignoredInput) dgPtr; } Not sure, if this is possible to handle at all...
Re: templatized delegate
On Tuesday, 23 May 2017 at 10:42:54 UTC, Nicholas Wilson wrote: On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is a bit weird to use, and probably affects performance. By the way, I'm not even sure, if variadics work in my case. I have a strange struct of a random generator, which cannot be copied, and I have no idea how to pass it to a variadic function: import std.stdio; import mir.random; void main() { Random rndGen = Random(unpredictableSeed); fun(rndGen); } void fun(...) { } Yields "... is not copyable because it is annotated with @disable" :) Random is copy @disabled to prevent incorrect use. Yes, I'm aware of this... You need to pass it by ref or pointer. I dont know if you can pass variables as ref to a variadic, but you should be able to pass it by address. fun(&rndGen); No, you can't pass a ref into a variadic... if the test above is written correct. And no, I can't pass it by adress, as I don't know apriori, whether the very parameter which gets the random generator is already a part of the variadic parameters, or a well defined ref parameter. Especially, there are some functions for both cases. While the argument list remains the same, the acceptor part is meant to work with it somehow. The other way around would be, to manipulate the argument list, which is shared...
Re: templatized delegate
On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is a bit weird to use, and probably affects performance. By the way, I'm not even sure, if variadics work in my case. I have a strange struct of a random generator, which cannot be copied, and I have no idea how to pass it to a variadic function: import std.stdio; import mir.random; void main() { Random rndGen = Random(unpredictableSeed); fun(rndGen); } void fun(...) { } Yields "... is not copyable because it is annotated with @disable" :) 1. Pass its pointer 2. Use variadic template with auto ref: ``` void foo(T...)(auto ref T tup) { } ```
Re: templatized delegate
On Tuesday, 23 May 2017 at 10:42:54 UTC, Nicholas Wilson wrote: On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is a bit weird to use, and probably affects performance. By the way, I'm not even sure, if variadics work in my case. I have a strange struct of a random generator, which cannot be copied, and I have no idea how to pass it to a variadic function: import std.stdio; import mir.random; void main() { Random rndGen = Random(unpredictableSeed); fun(rndGen); } void fun(...) { } Yields "... is not copyable because it is annotated with @disable" :) Random is copy @disabled to prevent incorrect use. You need to pass it by ref or pointer. I dont know if you can pass variables as ref to a variadic, but you should be able to pass it by address. fun(&rndGen); void variadic(Args...)(auto ref Args args) { /* ... */ } This infers whether you pass lvalues or rvalues. If passing further down the chain of such calls is needed, one can use std.functional : fowrard : void variadic(Args...)(auto ref Args args) { import std.functional : forward; doStuff(forward!args); } void doStuff(Args...)(auto ref Args args) { /* ... */ } 'forward' aliases ref arguments (i.e. passed lvalues) and moves value arguments (i.e. passed rvalues). If a value is not copyable, it may be move-able (check the docs though, it may not be that either). void fun(Args...)(auto ref Args args) { /*...*/ } import std.algorithm : move; auto a = NonCopyable(42); fun(move(a)); // or: func(NonCopyable(42));
Re: templatized delegate
On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is a bit weird to use, and probably affects performance. By the way, I'm not even sure, if variadics work in my case. I have a strange struct of a random generator, which cannot be copied, and I have no idea how to pass it to a variadic function: import std.stdio; import mir.random; void main() { Random rndGen = Random(unpredictableSeed); fun(rndGen); } void fun(...) { } Yields "... is not copyable because it is annotated with @disable" :) Random is copy @disabled to prevent incorrect use. You need to pass it by ref or pointer. I dont know if you can pass variables as ref to a variadic, but you should be able to pass it by address. fun(&rndGen);
Re: templatized delegate
On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is a bit weird to use, and probably affects performance. By the way, I'm not even sure, if variadics work in my case. I have a strange struct of a random generator, which cannot be copied, and I have no idea how to pass it to a variadic function: import std.stdio; import mir.random; void main() { Random rndGen = Random(unpredictableSeed); fun(rndGen); } void fun(...) { } Yields "... is not copyable because it is annotated with @disable" :)
Re: Which editor to use for editing DDOCs?
On Tue, 2017-05-23 at 07:40 +, biocyberman via Digitalmars-d-learn wrote: > […] > Adding DDOC support for D Mode require some more work obviously. > I will see if I can make some changes to that. For the time > being, I would like to know which editors people are using. Or is > it a plain black and white editor ? Until IntelliJ IDEA and/or CLion works for D, Emacs is my only D editor. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Which editor to use for editing DDOCs?
On Monday, 22 May 2017 at 15:33:36 UTC, Russel Winder wrote: 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 Emacs D Mode as far as I know. There is some attempt to do things for Doxygen, but I am not sure how successful that is as I am not using it. It is not clear to me that all D's comment mechanisms are handled as they should be. It should be possible, albeit non-trivial I suspect, to add support for all the comment forms and the DDOC macro markup. The question does anyone have the energy to get stuck into the E-Lisp to achieve the goal – and write the tests to prove it? Adding DDOC support for D Mode require some more work obviously. I will see if I can make some changes to that. For the time being, I would like to know which editors people are using. Or is it a plain black and white editor ?
Re: [OT] #define
On Tuesday, 23 May 2017 at 00:14:43 UTC, Mike Parker wrote: 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. APIENTRY is defined somewhere in the Win32 headers. IIRC, it's an alias for WINAPI, which is also defined in the Win32 headers to declare the standard call calling convention (which is __stdcall on the MS compiler and something else, I think, on GCC). OpenGL includes windows.h on Windows, so the Win32-specific stuff is there. The functions aren't in any Win32-specific sections. [] Much appreciated Mike and everyone else. I was able to make a good deal of progress today because of your input. Andrew
Re: trait detecting anonymous union?
On Tuesday, 23 May 2017 at 01:02:59 UTC, Vladimir Panteleev wrote: 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/rclidasm/meta.d#L110-L183 Interesting work. Thanks or sharing! Bastiaan.
Re: trait detecting anonymous union?
On Monday, 22 May 2017 at 22:11:15 UTC, Stanislav Blinov wrote: 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? There isn't a built-in one. The best I can muster at 1AM is finding all fields that have the same offset: Good idea, thanks for staying up while I was asleep :-)
Re: "if" is not evaluated for fields of Class.tupleof
On Tuesday, 23 May 2017 at 06:42:55 UTC, Timoses wrote: 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; } ``` Don't cast arbitrary types to classes, you're going to stumble upon very nasty surprises :) I guess you meant struct? Classes in D are quite fat, and don't start with data members right away, bookkeeping ClassInfo data comes first.