views:

93

answers:

1

We can have a local class defined inside a function but this class cannot be a template which is bit annoying and inconsistent. Is there any update on that in C++0x standard?

A: 

Yes. Actually this rule change is what makes Lambda expressions possible since a Lambda expression creates a local unnamed type.

Sorry, I misread your question. I thought you were talking about using a local class as template parameter. This wasn't allowed in C++98 and C++03 but it will work in C++0x.

As for your actual question, C++0x will not change any of this.

I honestly see no reason to allow "function-local class templates". The support for "function-local class templates" is a feature that probably only a handful of people care about. And writing class templates outside of functions is an acceptable substitute for this. This obviously doesn't put enough pressure on the compiler vendors no matter how complicated it is to implement such a feature. Compiler vendors are probably more concerned about implementing other C++0x features.

But I understand your point. It may seem as an unnecessary irregularity of the language. If you care strongly about this feature you could write a formal proposal and send it to the C++ standardization committee in about two years when they are likely to accept proposals for "C++1y".

sellibitze
In contrary I don't see a reason to disallow a local template class. I have no idea why this is disabled in the standard C++
valdo
@valdo: have you ever written a compiler ? or browse a compiler's code ? From a usability point of view it could be nice, but from a compiler writer's point of view it adds an ungodly amount of complexity for a niche functionality: it ain't worth it.
Matthieu M.
@Matthieu M: It probably wouldn't be hard if you'd design it in from scratch, but this is basically a legacy problem. Function scope comes from C, and the code is likely independent from that of namespaces. But if you had implemented functions as a kind of namespace, such features would come for free.
MSalters
@sellibitze but then you have to answer to the question: what's more important easy life for compiler writers and they should only implement easy to do features or better tools for programmers?
There is nothing we can do
@MSalters: If C++ had been designed from scratch ? There isn't a week I don't wish for it :)
Matthieu M.
@There is nothing we can do: what's more important ? That the code works. Compiler writers are normal people, with schedules, leisure time etc... they thus only have a finite amount of time to handle things, and thus they have to choose what they can implement in that amount of time. Furthermore, the more complicated the compiler work, the slower it'll go, and I bet you care about compilation time. So that a very misguided remark... indeed. And I am not @sellibitze.
Matthieu M.
@Matthieu the code should works and it doesn't matter how it is difficult to implement compiler to do so. I don't like your approach that justifies not perfect software or potential software by saying that compiler writers have to have leisure time. Of course they should have as well as working time leisure time but it is not the point. The point is that we should aim to have as perfect software as possible and by saying that it is impossible you're just one of the people thanks to whom we have generally software which isn't even good and could be if people would stop fussing over.
There is nothing we can do
continue their precious leisure time etc. Either you are employed at certain position and you do your work or if you are not happy with that - leave but don't say that it's enough if code just works. That's so lame. That's so Java.
There is nothing we can do
@Mattieu another thing is that I do not care how compiler code looks like, I don't wanna see it, I do not feel sorry for compiler writers - it's their job as simple as this
There is nothing we can do
@Mattieu and if I have a choice I always chose tools with more power and which let me do perfect job over tool with speed in which this tool will allow me just to do a mediocre job. That's why I learn C++ not Java or MJ even though in those two latter languages it's quite easy (you can do things faster) but they are so constrain in so many ways that the traid off it's just isn't worth it.
There is nothing we can do
@There is nothing we can do: It is unreasonable to expect perfection. I am not saying that I do not wish for local template function / classes within functions... but I do dislike your tone and mindset, so I'll make it short: want them ? feel free to contribute to an open-source compiler and "stop fussing over".
Matthieu M.
@Matthieu it's not me who fusses over. It's you (your first and third comment). . And thanks to people like you we have 99% of software that just works and nothing else.
There is nothing we can do
@There is nothing we can do: that's where we disagree, I don't consider feature bloat "good". I much prefer a stable compiler to a bloated one. There are other features I'd prefer over this (lambdas, threading...), and this is not necessary (there are workarounds that don't cost much more).
Matthieu M.
@Matthieu I agree with the fact that stable is preferrable over bloated but that's very abstract and subjective. What bloated means for you and what it means for me? Is VS2010 bloated and unstable - to me sure it is. Is it slow, much slower than 2008 ver sure it is but even on that they are some people which did disagreed with me and were saying that they don't see any difference in performance between 2010 and 2008.
There is nothing we can do
@There is nothing we can do: we agree it's subjective then :) That is why the C++ standard is driven by an ISO committee which include members of the industry and compiler writers among others, and these people judged that the effort for such a request was not worth it... for C++0x. They may very well deem it suitable for the next standard, especially since Concepts should make it in, so perhaps that C++1x will be more template-friendly than thread-friendly.
Matthieu M.