But why aren't they non-static members? If they were non-static members the structure's size would still be compile-time, computed by the sum of sizes of all template instances. the .sizeof would work perfectly well.
You have. Its real size is 1, and the template instantiations are not memberOn 2012-39-05 09:12, Gor Gyolchanyan <gor.f.gyolchanyan@gmail.com> wrote:
Consider this piece of code:
struct Test
{
template member(Type)
{
Type member;
}
}
unittest
{
Test test;
test.member!int = 0;
test.member!long = 0;
test.member!short = 0;
import std.stdio; writeln(test.sizeof);
assert(test.sizeof == int.sizeof + long.sizeof + short.sizeof); // fails
assert(test.sizeof == 1); // succeeds
}
I don't get why the structure's size remains unchanged even after
instantiating 3 members inside it.
How can I get the real size of the structure, including all its members
(template or not)?
fields.
A template (not a templated function [actually, sorta, but that's a different
discussion]) is basically static - if you try instead Test.member!int, you
will see that this works perfectly.
What we see here is another example of the confusion that can be caused by
static names being accessible through an instance:
struct Foo {
static int n;
}
Foo f;
f.n = 4;
--
Simen