mirror of https://github.com/aria2/aria2
2010-09-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed TripletGet as TupleGet. Renamed TripletNthType as TupleNthType. Renamed Triplet2Pair as Tuple2Pair. * src/RequestGroupMan.cc * src/Triplet.h * test/TripletTest.ccpull/1/head
parent
6a07182b0d
commit
6c348f0493
|
@ -1,3 +1,11 @@
|
|||
2010-09-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Renamed TripletGet as TupleGet. Renamed TripletNthType as
|
||||
TupleNthType. Renamed Triplet2Pair as Tuple2Pair.
|
||||
* src/RequestGroupMan.cc
|
||||
* src/Triplet.h
|
||||
* test/TripletTest.cc
|
||||
|
||||
2010-09-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Use class instead of typename for Triplet template parameter.
|
||||
|
|
|
@ -932,7 +932,7 @@ void RequestGroupMan::getUsedHosts
|
|||
}
|
||||
std::sort(tempHosts.begin(), tempHosts.end());
|
||||
std::transform(tempHosts.begin(), tempHosts.end(),
|
||||
std::back_inserter(usedHosts), Triplet2Pair<1, 3>());
|
||||
std::back_inserter(usedHosts), Tuple2Pair<1, 3>());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -84,65 +84,65 @@ Triplet<T1, T2, T3> makeTriplet(const T1& t1, const T2& t2, const T3& t3)
|
|||
return Triplet<T1, T2, T3>(t1, t2, t3);
|
||||
}
|
||||
|
||||
template<class Triplet, size_t N>
|
||||
struct TripletNthType;
|
||||
template<class Tuple, size_t N>
|
||||
struct TupleNthType;
|
||||
|
||||
template<class Triplet>
|
||||
struct TripletNthType<Triplet, 1> {
|
||||
typedef typename Triplet::first_type type;
|
||||
template<class Tuple>
|
||||
struct TupleNthType<Tuple, 1> {
|
||||
typedef typename Tuple::first_type type;
|
||||
};
|
||||
|
||||
template<class Triplet>
|
||||
struct TripletNthType<Triplet, 2> {
|
||||
typedef typename Triplet::second_type type;
|
||||
template<class Tuple>
|
||||
struct TupleNthType<Tuple, 2> {
|
||||
typedef typename Tuple::second_type type;
|
||||
};
|
||||
|
||||
template<class Triplet>
|
||||
struct TripletNthType<Triplet, 3> {
|
||||
typedef typename Triplet::third_type type;
|
||||
template<class Tuple>
|
||||
struct TupleNthType<Tuple, 3> {
|
||||
typedef typename Tuple::third_type type;
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct TripletGet;
|
||||
struct TupleGet;
|
||||
|
||||
template<>
|
||||
struct TripletGet<1> {
|
||||
template<class Triplet>
|
||||
static typename TripletNthType<Triplet, 1>::type get(const Triplet& tri)
|
||||
struct TupleGet<1> {
|
||||
template<class Tuple>
|
||||
static typename TupleNthType<Tuple, 1>::type get(const Tuple& tri)
|
||||
{
|
||||
return tri.first;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct TripletGet<2> {
|
||||
template<class Triplet>
|
||||
static typename TripletNthType<Triplet, 2>::type get(const Triplet& tri)
|
||||
struct TupleGet<2> {
|
||||
template<class Tuple>
|
||||
static typename TupleNthType<Tuple, 2>::type get(const Tuple& tri)
|
||||
{
|
||||
return tri.second;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct TripletGet<3> {
|
||||
template<class Triplet>
|
||||
static typename TripletNthType<Triplet, 3>::type get(const Triplet& tri)
|
||||
struct TupleGet<3> {
|
||||
template<class Tuple>
|
||||
static typename TupleNthType<Tuple, 3>::type get(const Tuple& tri)
|
||||
{
|
||||
return tri.third;
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N1, size_t N2>
|
||||
class Triplet2Pair {
|
||||
class Tuple2Pair {
|
||||
public:
|
||||
template<class Triplet>
|
||||
std::pair<typename TripletNthType<Triplet, N1>::type,
|
||||
typename TripletNthType<Triplet, N2>::type>
|
||||
operator()(const Triplet& tri) const
|
||||
template<class Tuple>
|
||||
std::pair<typename TupleNthType<Tuple, N1>::type,
|
||||
typename TupleNthType<Tuple, N2>::type>
|
||||
operator()(const Tuple& tri) const
|
||||
{
|
||||
return std::make_pair<typename TripletNthType<Triplet, N1>::type,
|
||||
typename TripletNthType<Triplet, N2>::type>
|
||||
(TripletGet<N1>::get(tri), TripletGet<N2>::get(tri));
|
||||
return std::make_pair<typename TupleNthType<Tuple, N1>::type,
|
||||
typename TupleNthType<Tuple, N2>::type>
|
||||
(TupleGet<N1>::get(tri), TupleGet<N2>::get(tri));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ class TripletTest:public CppUnit::TestFixture {
|
|||
|
||||
CPPUNIT_TEST_SUITE(TripletTest);
|
||||
CPPUNIT_TEST(testLess);
|
||||
CPPUNIT_TEST(testTripletGet);
|
||||
CPPUNIT_TEST(testTripletNthType);
|
||||
CPPUNIT_TEST(testTriplet2Pair);
|
||||
CPPUNIT_TEST(testTupleGet);
|
||||
CPPUNIT_TEST(testTupleNthType);
|
||||
CPPUNIT_TEST(testTuple2Pair);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
@ -18,9 +18,9 @@ public:
|
|||
void tearDown() {}
|
||||
|
||||
void testLess();
|
||||
void testTripletGet();
|
||||
void testTripletNthType();
|
||||
void testTriplet2Pair();
|
||||
void testTupleGet();
|
||||
void testTupleNthType();
|
||||
void testTuple2Pair();
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TripletTest);
|
||||
|
@ -44,32 +44,32 @@ void TripletTest::testLess()
|
|||
CPPUNIT_ASSERT(!(tri6 < tri5));
|
||||
}
|
||||
|
||||
void TripletTest::testTripletGet()
|
||||
void TripletTest::testTupleGet()
|
||||
{
|
||||
Triplet<int, double, std::string> x(1, 3.14, "foo");
|
||||
CPPUNIT_ASSERT_EQUAL(1, (TripletGet<1>::get(x)));
|
||||
CPPUNIT_ASSERT_EQUAL((double)3.14, (TripletGet<2>::get(x)));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo"), (TripletGet<3>::get(x)));
|
||||
CPPUNIT_ASSERT_EQUAL(1, (TupleGet<1>::get(x)));
|
||||
CPPUNIT_ASSERT_EQUAL((double)3.14, (TupleGet<2>::get(x)));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo"), (TupleGet<3>::get(x)));
|
||||
}
|
||||
|
||||
void TripletTest::testTripletNthType()
|
||||
void TripletTest::testTupleNthType()
|
||||
{
|
||||
TripletNthType<Triplet<int, double, std::string>, 1>::type x = 1;
|
||||
TupleNthType<Triplet<int, double, std::string>, 1>::type x = 1;
|
||||
CPPUNIT_ASSERT_EQUAL(1, x);
|
||||
TripletNthType<Triplet<int, double, std::string>, 2>::type y = 3.14;
|
||||
TupleNthType<Triplet<int, double, std::string>, 2>::type y = 3.14;
|
||||
CPPUNIT_ASSERT_EQUAL((double)3.14, y);
|
||||
TripletNthType<Triplet<int, double, std::string>, 3>::type z = "foo";
|
||||
TupleNthType<Triplet<int, double, std::string>, 3>::type z = "foo";
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo"), z);
|
||||
}
|
||||
|
||||
void TripletTest::testTriplet2Pair()
|
||||
void TripletTest::testTuple2Pair()
|
||||
{
|
||||
Triplet<int, double, std::string> x(1, 3.14, "foo");
|
||||
std::pair<int, double> p1 = Triplet2Pair<1, 2>()(x);
|
||||
std::pair<int, double> p1 = Tuple2Pair<1, 2>()(x);
|
||||
CPPUNIT_ASSERT_EQUAL(1, p1.first);
|
||||
CPPUNIT_ASSERT_EQUAL((double)3.14, p1.second);
|
||||
|
||||
std::pair<double, std::string> p2 = Triplet2Pair<2, 3>()(x);
|
||||
std::pair<double, std::string> p2 = Tuple2Pair<2, 3>()(x);
|
||||
CPPUNIT_ASSERT_EQUAL((double)3.14, p2.first);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo"), p2.second);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue