Template function bug - or am i a retard? you decide.
Neal Alexander
wqeqweuqy at hotmail.com
Thu Dec 20 10:00:18 PST 2007
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.
More information about the Digitalmars-d-learn
mailing list