Default template arguments in function templates

G

George Sakkis

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
 
V

Victor Bazarov

George said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top