Re: Match properties as member variables

2013-12-15 Thread comco
On Sunday, 15 December 2013 at 23:38:57 UTC, comco wrote: On Sunday, 15 December 2013 at 23:13:39 UTC, Jakob Ovrum wrote: On Friday, 13 December 2013 at 12:01:28 UTC, comco wrote: From client perspective, properties look like member variables. With (auto) ref, a generic function can catch a

Re: Match properties as member variables

2013-12-15 Thread comco
On Sunday, 15 December 2013 at 23:13:39 UTC, Jakob Ovrum wrote: On Friday, 13 December 2013 at 12:01:28 UTC, comco wrote: From client perspective, properties look like member variables. With (auto) ref, a generic function can catch a member variable and read it and update it: void swap(T

Re: Match properties as member variables

2013-12-15 Thread comco
On Friday, 13 December 2013 at 12:01:28 UTC, comco wrote: From client perspective, properties look like member variables. With (auto) ref, a generic function can catch a member variable and read it and update it: void swap(T)(ref T a, ref T b) {...} The client can use swap with member

Re: static if - is the 'static' really needed?

2013-12-13 Thread comco
On Friday, 13 December 2013 at 12:50:01 UTC, Nicolas Sicard wrote: On Friday, 13 December 2013 at 12:10:02 UTC, comco wrote: Imagine a world in which a simple 'if' has the semantics of a static if, if the condition is evaluable at CT. Is this a world you would rather live in? te

static if - is the 'static' really needed?

2013-12-13 Thread comco
Imagine a world in which a simple 'if' has the semantics of a static if, if the condition is evaluable at CT. Is this a world you would rather live in? template Fac(int i) { if (i == 0) { // static if; doesn't introduce scope enum Fac = 1; } else { enum Fac = i * Fac!(i-1); } } // If the condi

Match properties as member variables

2013-12-13 Thread comco
From client perspective, properties look like member variables. With (auto) ref, a generic function can catch a member variable and read it and update it: void swap(T)(ref T a, ref T b) {...} The client can use swap with member variables. But he can't use this swap with class properties - they

Re: Lazy template arguments?

2013-01-13 Thread comco
On Sunday, 13 January 2013 at 11:26:57 UTC, monarch_dodra wrote: Bearophile: Is this proposal a pure optimization trick, or is there some functionality gains here. The only one I can think of, is if "Foo!B" would fail to compile. Is this what you are going for...? Also: // template Ternar

Re: Lazy template arguments?

2013-01-13 Thread comco
On Saturday, 5 January 2013 at 10:37:31 UTC, bearophile wrote: In some case I'd like a hypothetical static ternary operator usable on types: alias T = (U.sizeof <= 16) ?? ushort : size_t; That is equivalent to: static if (U.sizeof <= 16) { alias T = ushort; } else { alias T = size_t;

Re: Variadic templates with aliases

2012-12-28 Thread comco
On Thursday, 27 December 2012 at 21:21:24 UTC, Philippe Sigaud wrote: On Thu, Dec 27, 2012 at 9:01 PM, comco wrote: I wrote a simple template mixin to hold common operator overloads: mixin template VectorSpaceOpsMixin(Vector, Scalar, alias a, alias b) { Vector opUnary(string op)() if

Variadic templates with aliases

2012-12-27 Thread comco
I wrote a simple template mixin to hold common operator overloads: mixin template VectorSpaceOpsMixin(Vector, Scalar, alias a, alias b) { Vector opUnary(string op)() if (op == "-") { return Vector(-a, -b); } ... } This works like this: struct complex { double a, b;

Re: assertion failure with template instantiation of forward reference class

2012-11-29 Thread comco
On Thursday, 29 November 2012 at 01:38:50 UTC, bearophile wrote: comco: Looks like a bug? This is what DMD 2.061alpha prints, it doesn't crash: ...\dmd2\src\phobos\std\range.d(603): Error: static assert "Cannot put a string into a LockingTextWriter" ...\dmd2\src\phobos\st

assertion failure with template instantiation of forward reference class

2012-11-28 Thread comco
When trying to compile this code: import std.stdio; class A; class B(T) : T { } void main() { writeln(typeid(B!A)); } I get this error: Assertion failure: '!scope' on line 358 in file 'toobj.c'. Shouldn't it be more like: Error: class main.A unable to resolve forward reference in definit

Re: constructor instead of opCall for an instance of a template alias

2012-11-25 Thread comco
On Sunday, 25 November 2012 at 16:01:39 UTC, Ali Çehreli wrote: Could you please create a bug report: http://d.puremagic.com/issues/ Ali Filed an issue 9078.

Re: constructor instead of opCall for an instance of a template alias

2012-11-25 Thread comco
A!B(...) defines a struct A with B typed in as Method, so call to method(s); is the same as B(string) Why is that? Here method is an instance of the type Method, not the type Method itself, so by saying `method(s)` we can't mean a constructor. Something very strange happens... I have a simple

constructor instead of opCall for an instance of a template alias

2012-11-24 Thread comco
I have the following snippet: struct A(alias Method) { string s; this(Method method) { method(s); // 5 } } struct B { this(int i) { } void opCall(string s) { } } void main() { A!B(B(0)); } This code fails to compile with the following errors: test.d(5): Error:

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread comco
On Monday, 24 September 2012 at 11:39:08 UTC, monarch_dodra wrote: Oh. I think I just got what your "reassign" was meant to do. I think I see it now. I guess it does work nice actually. I'd say that unfortunately, your *new* reassign is making the assumption that it is possible to grab a refe

Re: alias to a property as an argument to a mixin template

2012-09-24 Thread comco
On Monday, 24 September 2012 at 07:00:37 UTC, monarch_dodra wrote: On Sunday, 23 September 2012 at 21:44:20 UTC, comco wrote: [SNIP] Now we can implement our rotate in terms of reassign: void rotate(node* u) { auto v = u.right; reassign(u.right, v.left, u); } This works and is

Re: alias to a property as an argument to a mixin template

2012-09-23 Thread comco
On Sunday, 23 September 2012 at 21:42:54 UTC, comco wrote: On Sunday, 23 September 2012 at 19:53:26 UTC, Philippe Sigaud wrote: monarch_dodra already answered, but since, I typed this, I may as well post it :) On Sun, Sep 23, 2012 at 8:49 PM, comco wrote: For this program I'm getti

Re: alias to a property as an argument to a mixin template

2012-09-23 Thread comco
On Sunday, 23 September 2012 at 19:53:26 UTC, Philippe Sigaud wrote: monarch_dodra already answered, but since, I typed this, I may as well post it :) On Sun, Sep 23, 2012 at 8:49 PM, comco wrote: For this program I'm getting an "Error: need 'this' to access member

alias to a property as an argument to a mixin template

2012-09-23 Thread comco
For this program I'm getting an "Error: need 'this' to access member x" at line (*). Does that mean that we cannot alias a property as an argument of a template mixin? import std.stdio; mixin template T(alias a) { void f() { writeln(a); // (*) } } s