comeau
Tue Aug 19 14:32:03 CDT 2003
In article <01n4kv8setfucphsdva98dgcjev79dr7er@4ax.com>,
Doug Harrison [MVP] <dsh@mvps.org> wrote:
>Greg Comeau wrote:
>>In article <e3e73a80.0308182342.3414ed8@posting.google.com>,
>>Programmer_blabla <programmer_blabla@hotmail.com> wrote:
>>>Ok many thx all:
>>>
>>>1) For the people responding 'why do you do this', answer: it was an
>>>academic question. Of course you can work with overloads etc.
>>>2) I posted earlier also a c++ problem which was correctly rejected by
>>>the compiler. At least some people and the Comeau compiler think so.
>>>Next time I let Comeau take a look at it. If it compiles we have a
>>>problem
>>>3) And some day maybe I will spend time trying to understand the whole
>>>unreadable c++ standard.
>>>
>>>Only strange thing is that the inline variant does compile
>>>
>>>template <typename T>
>>>class KAEx_T
>>>{
>>>public:
>>> template <typename U>
>>> void Foo(const U& rU)
>>> {}
>>>
>>> template <>
>>> void Foo(const std::string& rstr)
>>> {}
>>>};
>>>
>>>which is either incorrectly accepted by VC++, or c++ is strange by
>>>allowing more or less the same concept depending on how its
>>>implemented.
>>
>>The above code is not valid accto Standard C++.
>>As you note VC++ accepts it (as does Comeau in MS mode,
>>but not in strict mode).
>
>Do you happen to know why it's forbidden?
The general rule is that (all) specializations be
in namespace scope. As I recall it, allowing it in
class scope was consider too messy, it would need lots
of special rules, involving ordering, accessibility, etc.
Consider for instance:
template <typename T>
class KAEx_T
{
public:
template <typename U>
void Foo(const U& rU)
{}
private:
template <>
void Foo(const std::string& rstr)
{}
};
It also seems to hijack specializations, in that you then can't
always specialize the class itself. IOWs, it was thought that
people may not want to be using this capability (many things
were possible, and the committee did have to control themselves
to allow the kitchen sink).
There was probably some corner cases too presented
at the time which either broke things or became
confusing even if the behavior could be defined.
--
Greg Comeau/4.3.3:Full C++03 core language + more Windows backends
Comeau C/C++ ONLINE ==>
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?