digitalmars.D.learn - Template function bug - or am i a retard? you decide.
- Neal Alexander (29/29) Dec 20 2007 class A
- BCS (2/8) Dec 20 2007 I don't think you can have non static template functions in a class
- Jarrett Billingsley (5/13) Dec 20 2007 Of course you can (though the spec still says otherwise). You can't hav...
class A { int x[]; void read_array(alias var, T = typeof(var))(...){ return; } void fail(){ read_array!(x)(); } } - test.d:5: template instance cannot use local 'x' as template parameter - gcc version 4.1.3 20070831 (prerelease gdc 0.25, using dmd 1.021) Moving [read_array] out of [A] or making [x] static "fixes" it. But i don't really want to have to pass a 'this' pointer to it every time i use it. Also: """ Changelog: What's New for D 0.173 Nov 1, 2006 New/Changed Features * Template instantiations can now accept alias parameters for local variables and nested functions. ... """ Is there any other/better way to produce the above in a template (without [block] being a specific type)? TypeInfo t = typeid(T); size_t size = ((t.next) ? t.next.tsize : t.tsize) * n; block = cast(typeof(block)) new byte[size]; so passing a uint32_t[] as [block] with [n = 10] would allocate 40 bytes and block.length would be 10. Or passing a uint32_t* to it would simply assign the allocated blocks address to it.
Dec 20 2007
Reply to Neal,class A { int x[]; void read_array(alias var, T = typeof(var))(...){ return; } void fail(){ read_array!(x)(); } }I don't think you can have non static template functions in a class
Dec 20 2007
"BCS" <ao pathlink.com> wrote in message news:ce0a3343270b28ca1114b0613b1a news.digitalmars.com...Reply to Neal,Of course you can (though the spec still says otherwise). You can't have _virtual_ templated methods in a class. Templated methods are implicitly final.class A { int x[]; void read_array(alias var, T = typeof(var))(...){ return; } void fail(){ read_array!(x)(); } }I don't think you can have non static template functions in a class
Dec 20 2007