mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 18:45:10 +01:00
fixed SF# 1883871: TypeList operator < fails for tuples with duplicate values
This commit is contained in:
parent
c3ff907751
commit
533f42bfce
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// TypeList.h
|
// TypeList.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
@ -126,10 +126,11 @@ struct TypeList
|
|||||||
|
|
||||||
bool operator < (const TypeList& tl) const
|
bool operator < (const TypeList& tl) const
|
||||||
{
|
{
|
||||||
bool smaller = (head < tl.head);
|
if (head < tl.head)
|
||||||
if (smaller)
|
return true;
|
||||||
return smaller;
|
else if (head == tl.head)
|
||||||
return tail < tl.tail;
|
return tail < tl.tail;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(TypeList& tl)
|
void swap(TypeList& tl)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// TuplesTest.cpp
|
// TuplesTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/TuplesTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/TuplesTest.cpp#3 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@ -36,6 +36,7 @@
|
|||||||
#include "Poco/Tuple.h"
|
#include "Poco/Tuple.h"
|
||||||
#include "Poco/Void.h"
|
#include "Poco/Void.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
using Poco::TypeList;
|
using Poco::TypeList;
|
||||||
@ -512,6 +513,45 @@ void TuplesTest::testTupleOrder()
|
|||||||
assert (tv[0] == aTuple);
|
assert (tv[0] == aTuple);
|
||||||
assert (tv[1] == aTuple2);
|
assert (tv[1] == aTuple2);
|
||||||
assert (tv[2] == aTuple3);
|
assert (tv[2] == aTuple3);
|
||||||
|
|
||||||
|
std::map<TupleType, int> tm;
|
||||||
|
std::pair<std::map<TupleType, int>::iterator, bool> mIt = tm.insert(std::map<TupleType, int>::value_type(aTuple2, 2));
|
||||||
|
assert (mIt.second);
|
||||||
|
mIt = tm.insert(std::map<TupleType, int>::value_type(aTuple, 1));
|
||||||
|
assert (mIt.second);
|
||||||
|
mIt = tm.insert(std::map<TupleType, int>::value_type(aTuple3, 3));
|
||||||
|
assert (mIt.second);
|
||||||
|
|
||||||
|
std::map<TupleType, int>::iterator fIt = tm.find(aTuple2);
|
||||||
|
assert (2 == fIt->second);
|
||||||
|
|
||||||
|
typedef Tuple<std::string, std::string, std::string, std::string> StrTup;
|
||||||
|
typedef std::map<StrTup, int> StrTupMap;
|
||||||
|
|
||||||
|
StrTup st1("123", "456", "789", "101112");
|
||||||
|
StrTup st2("123", "456", "101112", "789");
|
||||||
|
StrTup st3("123", "789", "789", "101112");
|
||||||
|
StrTup st4("123", "101112", "456", "789");
|
||||||
|
|
||||||
|
testTupleStrictWeak(st2, st1, st3);
|
||||||
|
|
||||||
|
StrTupMap strMap;
|
||||||
|
strMap.insert(StrTupMap::value_type(st1, 1));
|
||||||
|
strMap.insert(StrTupMap::value_type(st2, 2));
|
||||||
|
strMap.insert(StrTupMap::value_type(st3, 3));
|
||||||
|
strMap.insert(StrTupMap::value_type(st4, 4));
|
||||||
|
|
||||||
|
assert (1 == strMap[st1]);
|
||||||
|
assert (2 == strMap[st2]);
|
||||||
|
assert (3 == strMap[st3]);
|
||||||
|
assert (4 == strMap[st4]);
|
||||||
|
|
||||||
|
StrTupMap::iterator it = strMap.begin();
|
||||||
|
assert (st4 == it->first); ++it;
|
||||||
|
assert (st2 == it->first); ++it;
|
||||||
|
assert (st1 == it->first); ++it;
|
||||||
|
assert (st3 == it->first); ++it;
|
||||||
|
assert (it == strMap.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user