A devil self reference
Alex
sascha.orlov at gmail.com
Wed Aug 15 16:40:49 UTC 2018
Hi all.
Finally, I arrived at something like this:
´´´
void main()
{
S!(sarr)[] sarr;
}
struct S(alias Reference)
{
size_t id()
in
{
// not static assert, only because a pointer is never known in
advance
assert(Reference.ptr <= &this);
}
do
{
return &this - Reference.ptr;
}
}
´´´
Of course, this does not compile, because I try to use an
identifier before I defined it.
However, the reason I dare to ask is, that all the stuff with the
weird self reference is compile time known.
So, is there a possibility to define something like the thing
above?
More information about the Digitalmars-d-learn
mailing list