digitalmars.D.learn - how to compose delegate type
- Ellery Newcomer (5/5) Dec 05 2013 how do I construct F!(T) to yield
- Jesse Phillips (10/15) Dec 05 2013 I don't think I understand what you mean:
- Ellery Newcomer (23/24) Dec 06 2013 this code illustrates it:
- Jesse Phillips (36/61) Dec 07 2013 This declaration doesn't make sense to me:
- Ellery Newcomer (3/7) Dec 07 2013 http://dlang.org/class.html#member-functions
- Jesse Phillips (22/31) Dec 07 2013 That isn't really the type of a delegate though. Outside of a
- Ellery Newcomer (6/9) Dec 08 2013 It composes the wrong type. It composes a type that has different
how do I construct F!(T) to yield void delegate() immutable when T is void delegate() ? [its been a long day]
Dec 05 2013
On Friday, 6 December 2013 at 02:42:44 UTC, Ellery Newcomer wrote:how do I construct F!(T) to yield void delegate() immutable when T is void delegate() ? [its been a long day]I don't think I understand what you mean: void main() { F!(void delegate()); } immutable(T) F(T)() { return () {}; } Initially I thought you meant T was a void delegate but passing delegates as compile time parameters isn't really an option.
Dec 05 2013
On 12/05/2013 09:33 PM, Jesse Phillips wrote:I don't think I understand what you mean:this code illustrates it: class Z { string a() immutable { return " 1"; } string b() { return "2"; } } template F(t) { alias immutable(t) F; } alias typeof(&Z.init.a) Texpected; alias typeof(&Z.init.a) T; static assert(is(F!(T) == Texpected)); void main() {} above F doesn't work; immutable(void delegate()) and void delegate() immutable are different types (I think the latter means 'this' is immutable). If t were a function pointer, you would apply the immutable to the pointer target like so: alias immutable(pointerTarget!t)* F
Dec 06 2013
On Saturday, 7 December 2013 at 01:18:06 UTC, Ellery Newcomer wrote:On 12/05/2013 09:33 PM, Jesse Phillips wrote:This declaration doesn't make sense to me: string a() immutable { return " 1"; } 'a' is already immutable (unless you consider the vtable, at which point: final string a(); would be immutable). The compiler spits out: static assert (is(immutable(string delegate()) == string delegate() immutable)) is false Which is strange because I don't see how immutability on 'a' means anything. And because of this I think your assertion is wrong: static assert(is(F!(T) == Texpected)); Is basically asking static assert(is(immutable(int) == int)); Which is not true, but this is (I've made modifications to your code): class Z { string a() { return " 1"; } string b() { return "2"; } } template F(t) { alias immutable(t) F; } alias typeof(&Z.init.a) Texpected; alias typeof(&Z.init.b) T; static assert(is(immutable(int) : int)); // Implicitly converts to static assert(is(int : immutable(int))); // Implicitly converts to static assert(is(F!(T) : Texpected)); // Implicitly converts to static assert(is(Texpected : F!(T) )); // Implicitly converts to void main() {}I don't think I understand what you mean:this code illustrates it: class Z { string a() immutable { return " 1"; } string b() { return "2"; } } template F(t) { alias immutable(t) F; } alias typeof(&Z.init.a) Texpected; alias typeof(&Z.init.a) T; static assert(is(F!(T) == Texpected)); void main() {} above F doesn't work; immutable(void delegate()) and void delegate() immutable are different types (I think the latter means 'this' is immutable). If t were a function pointer, you would apply the immutable to the pointer target like so: alias immutable(pointerTarget!t)* F
Dec 07 2013
On Saturday, 7 December 2013 at 19:36:50 UTC, Jesse Phillips wrote:This declaration doesn't make sense to me: string a() immutable { return " 1"; }http://dlang.org/class.html#member-functions
Dec 07 2013
On Saturday, 7 December 2013 at 23:02:18 UTC, Ellery Newcomer wrote:On Saturday, 7 December 2013 at 19:36:50 UTC, Jesse Phillips wrote:That isn't really the type of a delegate though. Outside of a class that usage has no meaning or value. Even so, I don't actually understand what value it brings over declaring the function const (maybe only callable by an immutable instance?). What is wrong with the current template which returns an immutable delegate type? It still store you're immutable member function. class Z { string a() immutable { return " 1"; } } template F(t) { alias immutable(t) F; } alias typeof(&Z.init.a) Texpected; alias typeof(&Z.init.a) T; static assert(is(F!(T) : Texpected)); static assert(is(Texpected : F!(T) )); void main() {}This declaration doesn't make sense to me: string a() immutable { return " 1"; }http://dlang.org/class.html#member-functions
Dec 07 2013
On Sunday, 8 December 2013 at 00:43:51 UTC, Jesse Phillips wrote:What is wrong with the current template which returns an immutable delegate type? It still store you're immutable member function.It composes the wrong type. It composes a type that has different constness than the target type, which will likely cause problems due to transitive const. Anyways, I'm trying to find a workaround to https://d.puremagic.com/issues/show_bug.cgi?id=11694
Dec 08 2013