P
pookiebearbottom
Just trying to learn some things about templates. Was wondering how
boost::tupple really works, but the headers were a bit confusing to me.
I know you get do something like the following, just want to know how
it works with the overloading of get<>().
boost::tupple<int,double> tup(1,2.0);
double d=tup.get<2>(); // equal 2.0
// simple set up,
template <class T1,class T2> class MyPair
{
public:
T1* m_t1;
T2* m_t2;
MyPair(T1* t1,T2* t2)
: m_t1(t1), m_t2(t2)
{}
// want to know how to do this
template <int J> T1* get() {return m_t1;}
// just wondering if I could do this
template <class J> J* get() {return 0;}
};
// can I specialize this way?
template <class T1,class T2> T1* MyPair<T1,T2>::get<1>() { return
m_t1;}
template <class T1,class T2> T2* MyPair<T1,T2>::get<2>() { return
m_t2;}
// specialized this way??!?!?
template <class T1,class T2> T1* MyPair<T1,T2>::get<T1>() { return
m_t1;}
template <class T1,class T2> T2* MyPair<T1,T2>::get<T2>() { return
m_t2;}
thanks
-sal
boost::tupple really works, but the headers were a bit confusing to me.
I know you get do something like the following, just want to know how
it works with the overloading of get<>().
boost::tupple<int,double> tup(1,2.0);
double d=tup.get<2>(); // equal 2.0
// simple set up,
template <class T1,class T2> class MyPair
{
public:
T1* m_t1;
T2* m_t2;
MyPair(T1* t1,T2* t2)
: m_t1(t1), m_t2(t2)
{}
// want to know how to do this
template <int J> T1* get() {return m_t1;}
// just wondering if I could do this
template <class J> J* get() {return 0;}
};
// can I specialize this way?
template <class T1,class T2> T1* MyPair<T1,T2>::get<1>() { return
m_t1;}
template <class T1,class T2> T2* MyPair<T1,T2>::get<2>() { return
m_t2;}
// specialized this way??!?!?
template <class T1,class T2> T1* MyPair<T1,T2>::get<T1>() { return
m_t1;}
template <class T1,class T2> T2* MyPair<T1,T2>::get<T2>() { return
m_t2;}
thanks
-sal