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 = &some_foo; } } unittest { S s; s.someState = 1; enable(); s.someState = 2; assert

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") m

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 b

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 writevalue

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 a

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, Ju

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 = debug;

Re: Class template argument deduction from constructor call

2010-10-29 Thread Juanjo Alvarez
On Wed, 27 Oct 2010 21:26:21 +0100, div0 wrote: this(T t) { this(string x) { this(int x) { autof0 = new Foo("wtf?"); autof1 = new Foo(42); Best match?

Re: Dispatching from receive to a function

2010-09-27 Thread Juanjo Alvarez
On Mon, 27 Sep 2010 21:00:48 +0200, Johannes Pfau wrote: > On 27.09.2010 20:46, Juanjo Alvarez wrote: >> I'm new to the language so I don't know if this is horribly wrong on >> some levels, but it works: >> >> - >>

Re: Dispatching from receive to a function

2010-09-27 Thread Juanjo Alvarez
I'm new to the language so I don't know if this is horribly wrong on some levels, but it works: - import std.variant; import std.stdio; class C { bool test(int i, char c) { writeln("Hello from test1"); return true; } void test2(string v) { writeln("Hello from

Re: Two questions about converting a C header file

2010-09-23 Thread Juanjo Alvarez
Auto reply, found both: 1. Just rename the varname, stupid stupid stupid! 2. import std.c.stdarg On Thu, 23 Sep 2010 19:44:44 +, Juanjo Alvarez wrote: > Hi, > > I'm converting a C header file but there are two things left: > > 1. If the header file contains some D

Two questions about converting a C header file

2010-09-23 Thread Juanjo Alvarez
Hi, I'm converting a C header file but there are two things left: 1. If the header file contains some D reserved word (in my case, "in" and "out" in a struct) what is the best way to workaround it? Do you write another C file and link about it? 2. What about va_list?

Re: Does the regex module support named captured groups?

2010-09-21 Thread Juanjo Alvarez
On Tue, 21 Sep 2010 16:22:22 -0400, bearophile wrote: You may add an enhancement request for Phobos in Bugzilla, asking for named captured groups, but there are many things to implement and only few people that implement things, so probably you will have to wait a lot of time :-) I guessed t

Does the regex module support named captured groups?

2010-09-21 Thread Juanjo Alvarez
In Python and C# you can define a regex like: "Blabla_(? \d{4}) _BLA And then if you match that against a string like: Blabla_1970_BLA you can get a hash with "year" as key and 1970 as value. Can this be done with D regex module? Trying it throws a RegExpException with the message "*+? not

Re: D equivalent of C++ reinterpret cast?

2010-09-19 Thread Juanjo Alvarez
On Sun, 19 Sep 2010 20:07:38 -0400, bearophile wrote: C standard say that's not safe. You can force that to be safe in C-GCC if you explicitly disable a compiler optimization. I think D docs don't say anything about this. And Walter has said that regarding such things D acts as C. So I am not

Re: Applying a tuple to a function (and more)

2010-09-19 Thread Juanjo Alvarez
Philippe Sigaud wrote: > What languages are you used to? You seem to do quite well with genericity > :) What I've done profesionally and personally in the last year would be 90% Python, 5% Java and 5% C++. So yes, since Python is like a D with an uberauto and everything being runtime templates

Re: Applying a tuple to a function (and more)

2010-09-19 Thread Juanjo Alvarez
Philippe Sigaud wrote: > String mixins are quite powerful, if a bit clunky at times. Both true, for what I'm seeing of them. > See also __traits(getMember, ...) > http://digitalmars.com/d/2.0/traits.html (look for getMember) Nice, with getMembers I could redesign again my test code for using

Re: Applying a tuple to a function (and more)

2010-09-18 Thread Juanjo Alvarez
Philippe Sigaud wrote: >> 1. Having the strings, defined at compile time, "MyClass" and "mymethod", >> how could I could I get to a delegate to MyClass.mymethod? >> > > You can insert them in a piece of code as a string, and then mix it in: > > enum string code = "auto deleg = &" ~ className ~

Applying a tuple to a function (and more)

2010-09-18 Thread Juanjo Alvarez
Hi, I've just arrived to D 2.0 and after reading Andrei's book I'm loving everything I'm seeing (except the bugs, of course). I wanted to ask how these would be done, because I can't find how to do it: 1. Having the strings, defined at compile time, "MyClass" and "mymethod", how could I could I