Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Default template arguments in function templates

Reply
Thread Tools

Default template arguments in function templates

 
 
George Sakkis
Guest
Posts: n/a
 
      10-04-2005
Hi all,

I have the following two template function definitions:

template <typename Container, typename Sepatator>
string join(const Container& c, const Sepatator& s) {
// ...
}

template <typename Container>
string join(const Container& c) {
return join(c, ' ');
}

I tried to merge them into one using a default argument for Separator, but the compiler (gcc 3.3.1)
complains that default template arguments may not be used in function templates. What's the reason
for this limitation and, more importantly, is there a workaround for it ?

TIA,
George



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-04-2005
George Sakkis wrote:
> I have the following two template function definitions:
>
> template <typename Container, typename Sepatator>
> string join(const Container& c, const Sepatator& s) {
> // ...
> }
>
> template <typename Container>
> string join(const Container& c) {
> return join(c, ' ');
> }
>
> I tried to merge them into one using a default argument for Separator, but the compiler (gcc 3.3.1)
> complains that default template arguments may not be used in function templates. What's the reason
> for this limitation and, more importantly, is there a workaround for it ?


Ask in comp.std.c++ bout the reasoning behind prohibiting the default
template arguments for function templates, they discuss the actual
Standard document, they know the rationales for different parts of it
for sure. As to the work-around, you already have it: don't merge, keep
the two functions separate.

V
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template template arguments and default parameters avasilev C++ 2 10-06-2011 01:40 PM
Design issue : "self type" as a default template argument (recursive template arguments) IR C++ 3 11-22-2006 08:38 PM
function default arguments from other arguments tutmann C++ 4 10-17-2006 08:00 PM
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
problem about "default template arguments may not be used in function templates " sods C++ 4 12-06-2005 08:01 AM



Advertisments