template<int n>
class NthElem{};
template<typename TL>
class Tuple;
template<>
class Tuple<Nil>{};
template<typename TL>
class Tuple
{
typedef typename TL::Head ElementType;
typedef typename Tuple<TL::Tail> RestType;
public:
// Get Functions
// =============
// Get function for the nth element.
template<int m>
typename boost::add_reference<
typename MetaNthType<TL, m>::Ret
>::type
Get()
{ return UglyGet(NthElem<m>()); };
// Ugly get function for the nth element, default
// implementation: look in the nested rest object.
template<int m>
typename boost::add_reference<
typename MetaNthType<TL, m>::Ret
>::type
UglyGet(NthElem<m>)
{ return m_rest.UglyGet(NthElem<m-1>()); };
// Ugly get function for the nth element, overload for m=0:
// return the element.
typename boost::add_reference<ElementType>::type
UglyGet(NthElem<0>)
{ return m_elem; };
private:
// Data members
// ============
ElementType m_elem;
RestType m_rest;
};
End of Listing