/* */ #ifndef D_TRIPLET_H #define D_TRIPLET_H #include #include namespace aria2 { template struct Triplet { typedef T1 first_type; typedef T2 second_type; typedef T3 third_type; T1 first; T2 second; T3 third; Triplet() {} Triplet(const T1& t1, const T2& t2, const T3& t3): first(t1), second(t2), third(t3) {} template Triplet(const Triplet& t): first(t.first), second(t.second), third(t.third) {} Triplet& operator=(const Triplet& tri) { if(this != &tri) { first = tri.first; second = tri.second; third = tri.third; } return *this; } }; template bool operator<(const Triplet& lhs, const Triplet& rhs) { return lhs.first < rhs.first || (!(rhs.first < lhs.first) && (lhs.second < rhs.second || (!(rhs.second < lhs.second) && lhs.third < rhs.third))); } template Triplet makeTriplet(const T1& t1, const T2& t2, const T3& t3) { return Triplet(t1, t2, t3); } template struct TupleNthType; template struct TupleNthType { typedef typename Tuple::first_type type; }; template struct TupleNthType { typedef typename Tuple::second_type type; }; template struct TupleNthType { typedef typename Tuple::third_type type; }; template struct TupleGet; template<> struct TupleGet<1> { template static typename TupleNthType::type get(const Tuple& tri) { return tri.first; } }; template<> struct TupleGet<2> { template static typename TupleNthType::type get(const Tuple& tri) { return tri.second; } }; template<> struct TupleGet<3> { template static typename TupleNthType::type get(const Tuple& tri) { return tri.third; } }; template class Tuple2Pair { public: template std::pair::type, typename TupleNthType::type> operator()(const Tuple& tri) const { return std::make_pair::type, typename TupleNthType::type> (TupleGet::get(tri), TupleGet::get(tri)); } }; } // namespace aria2 #endif // D_TRIPLET_H