Replace (ie: substitute) a type in varadic args

2016-08-02 Thread Saurabh Das via Digitalmars-d-learn
How can I substitute the type of an argument received via a varadic template? For example say I want to generalise this scenario: auto myConverterFunction1(bool arg1, bool arg2, ubyte arg3, int arg4) { return targetFunction(cast(ubyte)arg1, cast(ubyte)arg2, arg3, arg4); } So I'll have

Re: Replace (ie: substitute) a type in varadic args

2016-08-02 Thread Sean Campbell via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 07:24:28 UTC, Saurabh Das wrote: How can I substitute the type of an argument received via a varadic template? For example say I want to generalise this scenario: auto myConverterFunction1(bool arg1, bool arg2, ubyte arg3, int arg4) { return targetFunction(ca

Re: Replace (ie: substitute) a type in varadic args

2016-08-02 Thread Saurabh Das via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 08:16:48 UTC, Sean Campbell wrote: On Tuesday, 2 August 2016 at 07:24:28 UTC, Saurabh Das wrote: [...] Just of the top of my head, using ugly string mixins, this: auto myConverterFunc(Args...)(Args args) { string genCode() { string code

Re: Replace (ie: substitute) a type in varadic args

2016-08-02 Thread Saurabh Das via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 08:20:22 UTC, Saurabh Das wrote: On Tuesday, 2 August 2016 at 08:16:48 UTC, Sean Campbell wrote: [...] Thanks. Yes that is one approach. I figured out another approach that seems decent: auto targetFunctionProxy(Args...)(Args args) { import std.meta; ret

Re: Replace (ie: substitute) a type in varadic args

2016-08-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 08:22:15 UTC, Saurabh Das wrote: On Tuesday, 2 August 2016 at 08:20:22 UTC, Saurabh Das wrote: On Tuesday, 2 August 2016 at 08:16:48 UTC, Sean Campbell wrote: [...] Thanks. Yes that is one approach. I figured out another approach that seems decent: auto targetF

Re: prolog and epilog code

2016-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/1/16 9:24 PM, Rufus Smith wrote: Can one add code that executes before the GC and any memory is normally allocated(even static) and after all of it was suppose to be released? Of course! You just have to modify druntime :) One thing you can do instead is compile without a D main function,

[Derelict-Lua] compiler error when lua_register is called

2016-08-02 Thread Jack via Digitalmars-d-learn
So basically I get the error "function button(lua_State* L) is not callable using argument types ()" whenever I try to lua_register a function. ``` lua_register(L,"button",button); ``` but whenever I use the function pointer I get the error "lua_register is not callable using argument types (lu

Never-returning functions

2016-08-02 Thread Enamex via Digitalmars-d-learn
I've tried to write an 'assert function' in D, one that doesn't trigger the 'function must return a value or assert' error. Basically something like: Never neverReturns() { assert(0); } or @noreturn auto neverReturns() { assert(0); } and int tryMe(bool f) { if(f) return 42; else nev

Re: Never-returning functions

2016-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/16 11:09 AM, Enamex wrote: I've tried to write an 'assert function' in D, one that doesn't trigger the 'function must return a value or assert' error. Basically something like: Never neverReturns() { assert(0); } or @noreturn auto neverReturns() { assert(0); } and int tryMe(bool f) {

Re: Never-returning functions

2016-08-02 Thread ketmar via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 15:18:31 UTC, Steven Schveighoffer wrote: What's wrong with assert(0) that you need to have a wrapper function for it? while this is a legitimate question, the comipler's inability to infer "noreturn" still drives me mad. but if compiler will suddenly be able to i

Re: Never-returning functions

2016-08-02 Thread Enamex via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 15:18:31 UTC, Steven Schveighoffer wrote: What's wrong with assert(0) that you need to have a wrapper function for it? -Steve Nothing wrong exactly. I just wanted some descriptive terms to use in some places. Like "unreachable()" or "unimplemented()". To be cle

Re: Never-returning functions

2016-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/16 11:34 AM, Enamex wrote: On Tuesday, 2 August 2016 at 15:18:31 UTC, Steven Schveighoffer wrote: What's wrong with assert(0) that you need to have a wrapper function for it? -Steve Nothing wrong exactly. I just wanted some descriptive terms to use in some places. Like "unreachable()"

Re: prolog and epilog code

2016-08-02 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 11:37:05 UTC, Steven Schveighoffer wrote: On 8/1/16 9:24 PM, Rufus Smith wrote: Can one add code that executes before the GC and any memory is normally allocated(even static) and after all of it was suppose to be released? Of course! You just have to modify drunti

Re: prolog and epilog code

2016-08-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main() should do it

DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?

2016-08-02 Thread Sai via Digitalmars-d-learn
I see that there are ports of go compiler on ev3dev (ARM, debian based) for controlling the EV3 lego mindstorm robot. (http://www.ev3dev.org/docs/libraries/) Is there a port of a D compiler for ARM? How about libraries? I need a basic file IO and console IO for controlling the robot. Thanks

Re: [Derelict-Lua] compiler error when lua_register is called

2016-08-02 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 14:23:55 UTC, Jack wrote: So basically I get the error "function button(lua_State* L) is not callable using argument types ()" whenever I try to lua_register a function. ``` lua_register(L,"button",button); ``` but whenever I use the function pointer I get the error

Re: prolog and epilog code

2016-08-02 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 16:30:08 UTC, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main() should do it It doesn't seem to be that easy! https://wiki.dlang.org/Runtime_internals If I do this then I

Re: prolog and epilog code

2016-08-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 17:04:08 UTC, Rufus Smith wrote: It doesn't seem to be that easy! _d_run_main is extern(C), not just extern. Then your code should work. You can also simplify more: --- import std.stdio; import core.runtime; extern(C) int main() { rt_init(); wri

Re: prolog and epilog code

2016-08-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 17:23:57 UTC, Adam D. Ruppe wrote: _d_run_main is extern(C), not just extern. Then your code should work. Also, you don't actually have to rt_init and rt_term if you do _d_run_main because it does it for you...

Re: prolog and epilog code

2016-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/16 1:04 PM, Rufus Smith wrote: On Tuesday, 2 August 2016 at 16:30:08 UTC, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main() should do it It doesn't seem to be that easy! https://wiki.dlang.org/

Re: prolog and epilog code

2016-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/16 1:26 PM, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 17:23:57 UTC, Adam D. Ruppe wrote: _d_run_main is extern(C), not just extern. Then your code should work. Also, you don't actually have to rt_init and rt_term if you do _d_run_main because it does it for you... I don't thin

function core.checkedint.muls cannot inline function

2016-08-02 Thread Etranger via Digitalmars-d-learn
Hi, I'm trying to use the module core.checkedint, but I have a problem and I don't know if it is a bug or me. This simple program compiles well in debug mode with dmd, but give me an error when I compile in release mode: Error: function core.checkedint.muls cannot inline function import co

Re: Why Does Dscanner Warn About a Missing toHash if opEquals is Defined?

2016-08-02 Thread BLM768 via Digitalmars-d-learn
On Sunday, 31 July 2016 at 18:57:50 UTC, Jack Stouffer wrote: Next question: what's the fastest hashing implementation that will provide the least collisions? Is there a hash implementation that's perfered for AAs? I've heard that FNV-1a is a decent general-purpose option, and it's fairly str

Re: prolog and epilog code

2016-08-02 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 17:25:21 UTC, Steven Schveighoffer wrote: On 8/2/16 1:04 PM, Rufus Smith wrote: On Tuesday, 2 August 2016 at 16:30:08 UTC, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main()

Re: function core.checkedint.muls cannot inline function

2016-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/16 2:09 PM, Etranger wrote: Hi, I'm trying to use the module core.checkedint, but I have a problem and I don't know if it is a bug or me. This simple program compiles well in debug mode with dmd, but give me an error when I compile in release mode: Error: function core.checkedint.muls ca

Re: prolog and epilog code

2016-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/16 2:25 PM, Rufus Smith wrote: So, something funky is going on. Any ideas? phobos is not being resolved. I don't use visualD, so I'm not sure what the issue is, it's probably a compiler or linker ordering issue. -Steve

Re: prolog and epilog code

2016-08-02 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 18:34:49 UTC, Steven Schveighoffer wrote: On 8/2/16 2:25 PM, Rufus Smith wrote: So, something funky is going on. Any ideas? phobos is not being resolved. I don't use visualD, so I'm not sure what the issue is, it's probably a compiler or linker ordering issue.

Re: function core.checkedint.muls cannot inline function

2016-08-02 Thread Etranger via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 18:32:42 UTC, Steven Schveighoffer wrote: On 8/2/16 2:09 PM, Etranger wrote: Hi, I'm trying to use the module core.checkedint, but I have a problem and I don't know if it is a bug or me. This simple program compiles well in debug mode with dmd, but give me an e

Re: prolog and epilog code

2016-08-02 Thread Rufus Smith via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 20:28:51 UTC, Rufus Smith wrote: On Tuesday, 2 August 2016 at 18:34:49 UTC, Steven Schveighoffer wrote: On 8/2/16 2:25 PM, Rufus Smith wrote: So, something funky is going on. Any ideas? phobos is not being resolved. I don't use visualD, so I'm not sure what the

Re: Cannot compare object.opEquals is not nogc

2016-08-02 Thread Mark J Twain via Digitalmars-d-learn
A hack is to create the gc code you in a function want to call, say does the "gc" opEquals. Then cast that function to a nogc version by first casting to a void*. This way you can call gc code from nogc code, by bypassing the compiler's ability to check. It will obviously break your code if you

opAssign is not callable because it is annotated with @disable with SysTime(Possible bug?)

2016-08-02 Thread Jean-Mathieu Deschenes via Digitalmars-d-learn
Hello, I am currently trying to improve the TOML library of: https://github.com/iccodegr/toml.d I get a really weird error: Error: function main.TOMLValue.opAssign is not callable because it is annotated with @disable I have tested this with dmd 2.071.1 and 2.068.0. Here is the code to re

Re: [Derelict-Lua] compiler error when lua_register is called

2016-08-02 Thread Jack via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 16:44:39 UTC, Mike Parker wrote: On Tuesday, 2 August 2016 at 14:23:55 UTC, Jack wrote: [...] lua_register takes function pointers that in the form of lua_CFunction, an alias you can find declared in derelict.lua.types [1]. As you'll see there, it is declared to

Error flabergastation

2016-08-02 Thread Mark J Twain via Digitalmars-d-learn
winmain.d(40): Error: found 'while' when expecting ';' following statement winmain.d(40): Error: unexpected ( in declarator winmain.d(40): Error: basic type expected, not & winmain.d(40): Error: found '&' when expecting ')' winmain.d(40): Error: found 'msg' when expecting ')' winmain.d(40): Error

Passing refs with delegates

2016-08-02 Thread Mark J Twain via Digitalmars-d-learn
It's nice to be able to pass delegates and functions as callbacks. A nice feature is something like R foo(R,Args...)(R function(Args) callback, Args args) { return callback(args); } There are two problems with this. One is that type deduction doesn't work. I have to explicitly specify the t

Re: DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?

2016-08-02 Thread rikki cattermole via Digitalmars-d-learn
On 03/08/2016 4:31 AM, Sai wrote: I see that there are ports of go compiler on ev3dev (ARM, debian based) for controlling the EV3 lego mindstorm robot. (http://www.ev3dev.org/docs/libraries/) Is there a port of a D compiler for ARM? How about libraries? I need a basic file IO and console IO for

Re: DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?

2016-08-02 Thread Seb via Digitalmars-d-learn
On Tuesday, 2 August 2016 at 16:31:30 UTC, Sai wrote: I see that there are ports of go compiler on ev3dev (ARM, debian based) for controlling the EV3 lego mindstorm robot. (http://www.ev3dev.org/docs/libraries/) Is there a port of a D compiler for ARM? How about libraries? I need a basic file

Re: Error flabergastation

2016-08-02 Thread Ali Çehreli via Digitalmars-d-learn
On 08/02/2016 06:56 PM, Mark J Twain wrote: winmain.d(40): Error: found 'while' when expecting ';' following statement winmain.d(40): Error: unexpected ( in declarator winmain.d(40): Error: basic type expected, not & winmain.d(40): Error: found '&' when expecting ')' winmain.d(40): Error: found '