Re: Member delegate/fp to another member in same object?

2017-05-02 Thread Juanjo Alvarez via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 17:08:11 UTC, Juanjo Alvarez wrote: Example: struct S { int someState; void some_foo() { return this. someState;} void delegate() foo; void enable() { foo = _foo; } } unittest { S s; s.someState = 1; enable(); s.someState = 2; assert(foo ==

Member delegate/fp to another member in same object?

2017-05-02 Thread Juanjo Alvarez via Digitalmars-d-learn
Hi! I would like to have a "proxy" delegate, let's call it "foo" that could point to a method or another, let's call them "fast_foo" or "slow_foo" on the same object. This way depending on some conditions I could switch at runtime from one set of methods to others with a "switchFoo(" fast")

Re: Practical difference between template "alias" arguments/normal generic arguments in this case?

2017-04-12 Thread Juanjo Alvarez via Digitalmars-d-learn
Thanks to both, I got it. Type templates for generic types, and alias for other things knowing that the instantiation is by symbol. Yes, the "alias this" in my message was a (double) brainfart, I actually wanted to write "alias template". In this case both functions had the same assembler

Practical difference between template "alias" arguments/normal generic arguments in this case?

2017-04-12 Thread Juanjo Alvarez via Digitalmars-d-learn
Hi! With "alias this" accepting runtime variables I'm struggling to understand the difference between a generic function with an "alias this" parameter and another one with a "runtime" parameter of template type. Example: // example code import std.stdio: writeln; void

how to resolve matches more than one template declaration?

2014-06-20 Thread Juanjo Alvarez via Digitalmars-d-learn
Hi, Newbie question: void foo(S)(S oneparam){} void foo(S)(S oneparam, int anotherParam){} alias fooStr = foo!string; Gives: Error: template test.foo matches more than one template declaration: How could I fix it so the alias aliases one of the two versions? Also, why can't fooStr be an

Re: Version() for unittest OR debug?

2014-06-12 Thread Juanjo Alvarez via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 06:50:08 UTC, Kagamin wrote: debug version = DebugOrUnittest; else version(unittest)version = DebugOrUnittest; version(DebugOrUnittest) { static assert(false,DebugOrUnittest); } I like this option more. I didn't knew you could assign to version. Thanks,

Re: Version() for unittest OR debug?

2014-06-11 Thread Juanjo Alvarez via Digitalmars-d-learn
On Tuesday, 10 June 2014 at 14:06:58 UTC, bearophile wrote: Juanjo Alvarez: Probably I pretty simple question, how could I mark some code to be compiled when in debug OR unittest mode? (or both, ||) At first I tough I could do: version(unittest, debug) {} You can define a enum boolean

Version() for unittest OR debug?

2014-06-10 Thread Juanjo Alvarez via Digitalmars-d-learn
Hi, Probably I pretty simple question, how could I mark some code to be compiled when in debug OR unittest mode? (or both, ||) At first I tough I could do: version(unittest, debug) {} but this doesn't work. Then I tried to define a new version: version(DebugOrUnittest) { version =