S
Shriramana Sharma
Hi -- in case of templates that take more than one parameter, I wondered if it would be possible to partially specialize it (if that's the correct technical term) and typedef it to something else, for example:
# include <iostream>
# include <vector>
template < typename T, unsigned int S >
struct tuple {
tuple () : vec(S) {}
T& operator [] ( unsigned int i ) { return vec.at(i) ; }
private:
std::vector<T> vec ;
} ;
template < typename T >
typedef tuple<T,2> pair<T> ;
However, the compiler complains saying:
typedef-template.cpp:13:20: error: no template named 'pair'; did you mean 'std:air'?
Apparently the following is one way to do it:
template < typename T >
struct pair : public tuple<T,2> {} ;
However I wonder, if I am able to do:
typedef tuple<double,2> twoDoubles ;
why can't I do:
template < typename T >
typedef tuple<T,2> pair<T> ;
# include <iostream>
# include <vector>
template < typename T, unsigned int S >
struct tuple {
tuple () : vec(S) {}
T& operator [] ( unsigned int i ) { return vec.at(i) ; }
private:
std::vector<T> vec ;
} ;
template < typename T >
typedef tuple<T,2> pair<T> ;
However, the compiler complains saying:
typedef-template.cpp:13:20: error: no template named 'pair'; did you mean 'std:air'?
Apparently the following is one way to do it:
template < typename T >
struct pair : public tuple<T,2> {} ;
However I wonder, if I am able to do:
typedef tuple<double,2> twoDoubles ;
why can't I do:
template < typename T >
typedef tuple<T,2> pair<T> ;