No default function template arguments?
LLeweLLyn Reese
llewelly@lifesupport.shutdown.com
Thu Apr 3 21:33:00 GMT 2003
"Eric Lemings" <eric@lemings.com> writes:
> [elemings@cyberia core]$ more Test01.cpp
>
> #include <list>
>
> class Foo { };
>
> template <class T>
> struct Pred {
> bool operator () (const Foo* f) {
> return (dynamic_cast<T*> (f) != NULL);
> }
> };
>
> typedef std::list<Foo*> FooList;
>
> template <class T, class P = Pred<T> >
> bool findFoo (const FooList& fooList) {
>
> return (false);
> }
>
> [elemings@cyberia core]$ g++ -g -Wall -frepo -c Test01.cpp
> Test01.cpp:16: default template arguments may not be used in function
> templates
>
> WTF? It's right there in Stroustrup, Chp. 13, Sect. 4.1.
ISO C++ 14882:1998, 14.1/9, fourth sentence:
[snip]
# ... A default template-argument shall not be specified in a function
# template declaration, or a function template definition ...
[snip]
However, active issue 226 proposes a change, see
http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#226
Unfortunately, it appears that change didn't make it into the TC
... (Bjarne Stroustrup, who sumbitted issue 226, uses the word
'misbegotten' to describe the rule you are complaining about.)
ISTR there are some papers somewhere on the same site discussing the
issue further, but ...
If you don't like the rule, submit a bug report requesting gcc's
behavior be changed to match issume 226's suggested resolution. But be
sure to mention issue 226, as otherwise your bug will likely be
closed with a reference to 14.1/9
More information about the Gcc-help
mailing list