Interesting anomaly

My n-dimensional class templates begin to become interesting. Especially cause I found an interesting way to access it's members. Cause all members aren't accessed dynamically (rather by generating access points during compilation), I had to create special methodes for accessing each member individually. That may sound simple, but in fact it's an interesting concepts due to it's ability to access subdimensions from every other subdimension! Image there's a chain of statically combined dimensions using template classes: each dimensions has it's own value and a member representing the next dimension. The chain can be ended by using void as the member of the the last dimension (partial template specialisation). Now can access each member by calling obj.val, obj.next.val, obj.next.next.val etc. That can automated with by creating several accessors like T& x() or T& y() and so on. Originally, I thought this wouldn't work as you can't for example access z() if you already use z() from the last third dimension. But well - due to the compiler beeing unable to know what exact methods are now available (partial specialisation) you can still define it and he'll only complain about it if you use it a way where he can detect, that this function won't work. Neat, eh? That's why I like template: they enable programmer to do so many interesting things that go much, much beyond the normal ways of defining class. And with such a construct it could be possible to combine different object dimensions without heavy rewrite. I'm very optimistic about this one.

No comments: