Afficher un message
Vieux 22/02/2008, 08h10   #1
toton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut template member specialization of template class

Hi,
How can I specialize a template member function for a template class.
eg, I have a tuple like class
enum dir_type{
dir_x,dir_y
};
template< typename C>
class pair_type{
typedef C value_type;
typedef pair_type<C> self_type;
private:
value_type x_;
value_type y_;
public:
pair_type(const value_type& x,const value_type& y) : x_(x),y_(y){}
template<dir_type d>
value_type& get();

};

and want to call like
typedef pair_type<int> PT;
PT p(10,12);
int x = p.get<dir_x>();

now I want to specialize template<dir_type d> value_type& get() for
dir_x and dir_y, without specializing class pair_type for C.
1) is it possible ? if, then what is the syntax ?
2) if possible, can I write such specializations in the header file
directly ?
3) if not possible, in which way I can do this (like the way boost
tuple returns, only instead of get<1> etc, I want to have the enums as
the name i.e get<dir_x>()

any is appreciated.
thanks
abir

  Réponse avec citation
 
Page generated in 0,04583 seconds with 9 queries