On Saturday, 15 December 2012 at 22:21:21 UTC, Philippe Sigaud wrote:
If you don't mind, could you see if your solutions work on the following
code:

http://dpaste.dzfl.pl/64025e0a


What you're doing here is a bit different (AFAICT). _A is a template, not a 'real' class. So, it has no classinfo. The only real type here is the
template instantiation you call A.

Honestly, I have trouble reading your code, even though mine look much like yours. I really do not get what you're trying to do. Maybe I'm too tired.


I'm not sure what part of the code you don't understand but as a whole, the code simply makes using nested structs "cheaper" by calculating the "outer"parents location. To do this, unfortunately requires templating both classes. This, then, adds nonsense for the user to use those classes. I do not want them to see _NestLevel or _Offset.

`mixin(StructNestType!("B", "b1"));` is basically the same as `B b1;`.

It just ends up creating `B!(ofs) b1` so that b1 contains it's own offset into it the class so the parent can be found.

If you wanted to hard code the offset you could simply do `B!(23) b1;` but that makes it hard to manage.

So, all the template code and stuff is there to allow for automatic offset calculations. (The compiler could do all this behind the scenes and make it completely transparent(or near so))

In any case, the code works and I've written a more detailed post somewhere in

http://forum.dlang.org/thread/[email protected] if you care to know more.






The real issue I'm having now is not having to mangle the names and hide the `_NestLevel` and `_Offset` dependencies.

alias works for the case of one template argument to _A. Simply `alias _A!(true) A`. But when I have more than one such as `class _A(T1, bool)` I can't do `alias _A!(T1, true) A(T1)` analogous to the first case.

Which, I guess, is why you guys decided to try to use templates, but I can't get it to work properly. Also, as I've mented, I'm trying to not use A instead of _A but I almost always get recursion issues. (if I try some of the suggestions other errors occur)






This is possibly because I want to design the code to work with a variable
number of arguments(hence my asking for the number of arguments of a
templated class in the other post).

e.g., I want

class A(..., bool _NestLevel = true) { }

then

A(...) a; to create an object. (note the _NestLevel is "hidden")

If A has only one template argument, _NestLevel, then I want this to
reduce to

A a;

Thanks.


You should try to use templated factory functions:

auto makeA(..., bool _NestLevel = true)
{
    return new A!(..., _NestLevel)();
}


Ok, I'm not familiar with these, I've seen a lot of "weird" notation dealing with a variable number of template args(I think it's `T...`?) and such. I'll play around with it and hopefully get somewhere ;)

Reply via email to