Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local class template

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?

like image 676
There is nothing we can do Avatar asked Sep 19 '10 16:09

There is nothing we can do


1 Answers

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".

like image 64
sellibitze Avatar answered Sep 20 '22 18:09

sellibitze