| Thread overview | |||||
|---|---|---|---|---|---|
|
December 20, 2007 Template function bug - or am i a retard? you decide. | ||||
|---|---|---|---|---|
| ||||
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.
| ||||
December 20, 2007 Re: Template function bug - or am i a retard? you decide. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Neal Alexander | 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
| |||
December 20, 2007 Re: Template function bug - or am i a retard? you decide. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | "BCS" <ao@pathlink.com> wrote in message news:ce0a3343270b28ca1114b0613b1a@news.digitalmars.com... > 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 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. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply