function template specialization

Hi,

Is it possible to specialize templated function with templated templates?

I'm not sure if it's possible, and if yes what is the proper syntax.

I would imagine it something like this :

1
2
3
4
5
6
7
8
9
10
11
12
13
template<class T>
class bar {};
template<class T>
class baz {};

template<class C1, class C2>
C1 foo( const C2& );

template<>
template<class T>
bar<T> foo< bar<T>, baz<T> >( const baz<T>& ) {
	//....
}


Last edited on
I don't think you can specialise template functions that way. You have to use function overloading.
1
2
3
4
5
6
template<typename T>
bar<T> foo( const baz<T>& bz )
{
     //......
 }
yes it is, but remember to put in a function name.
I don't think you can specialise template functions that way. You have to use function overloading.


I tought of that, but I need to use two type of overloaded version of this func, with the only difference in the return value, like:

1
2
3
4
5
6
7
8
9
10
11
template<typename T>
bar<T> foo( const baz<T>& bz ) {
     //......
}

template<typename T>
bar_baz<T> foo( const baz<T>& bz ) {
     //......
}

bar_baz<int> h = foo( baz<int>() ); //ambigouos call 


I tought it would be nice to use the same function name for both, but than it seems I'm gonna have to use functions with different names :)

can you overload return types?
No, you can't overload on return types.
Topic archived. No new replies allowed.