
"Daniel James" <daniel@calamity.org.uk> wrote
Arkadiy Vertleyb wrote:
This introduces the problem of naming such classes. You employ __LINE__ to solve it, but I don't believe it's enough, since problems can easily pop up when envoking typeof from different files.
I don't just use __LINE__, I also use the name of the typedef. I think this should be unique within the current namespace. The line number probably isn't needed at all. But, if this isn't acceptable then it could define a named struct, with the type as a member, i.e. the user would name the struct, and then get the type using 'name::type'.
Agreed, but this makes typedef-oriented syntax a pre-requisit rather than just an example. Actually I agree that comming up with a solution that would require only as many foo<pos>() instantiations as needed (maybe it's already time to change this function's name) would be very attractive, since it would remove that constant time that can become quite noticable for simple types. Unfortunaly, for the reasons I mentioned in my previous post, I don't believe that it can be achieved without generating templates on the call site... Regards, Arkadiy