#include <QtCore/QCoreApplication>
#include <QMultiHash>
#include <QDebug>
#include <QString>
template <class T1, class T2>
struct stEvPairKey : QPair<T1, T2>
{
stEvPairKey() : QPair<T1, T2>() {}
stEvPairKey(const T1 &t1, const T2 &t2) : QPair<T1, T2>(t1, t2) {}
};
template <class T1, class T2>
bool operator==(const stEvPairKey<T1, T2> &p1, const stEvPairKey<T1, T2> &p2)
{
qDebug()<<"comparison";
return (p1.first == p2.first) && (p1.second & p2.second);
}
template <class T1, class T2>
quint32 qHash(const stEvPairKey<T1,T2>&key)
{
qDebug()<<"hash: " << qHash((QPair<T1,T2>)key);
return qHash((QPair<T1,T2>)key);
}
enum EFlags
{
NONE_FLAGS = 0,
FLAG1 = 1,
FLAG2 = 2,
FLAG3 = 4,
};
int main(int argc, char *argv[])
{
QHash<stEvPairKey<int, unsigned long>, bool> m_hash;
m_hash.insert(stEvPairKey<int, unsigned long>(1, FLAG1 | FLAG3), true);
if(m_hash.contains(stEvPairKey<int, unsigned long>(1, FLAG1)))
qDebug()<<"FLAG1: true";
if(m_hash.contains(stEvPairKey<int, unsigned long>(1, FLAG1 | FLAG3)))
qDebug()<<"FLAG1 | FLAG3: true";
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QMultiHash>
#include <QDebug>
#include <QString>
template <class T1, class T2>
struct stEvPairKey : QPair<T1, T2>
{
stEvPairKey() : QPair<T1, T2>() {}
stEvPairKey(const T1 &t1, const T2 &t2) : QPair<T1, T2>(t1, t2) {}
};
template <class T1, class T2>
bool operator==(const stEvPairKey<T1, T2> &p1, const stEvPairKey<T1, T2> &p2)
{
qDebug()<<"comparison";
return (p1.first == p2.first) && (p1.second & p2.second);
}
template <class T1, class T2>
quint32 qHash(const stEvPairKey<T1,T2>&key)
{
qDebug()<<"hash: " << qHash((QPair<T1,T2>)key);
return qHash((QPair<T1,T2>)key);
}
enum EFlags
{
NONE_FLAGS = 0,
FLAG1 = 1,
FLAG2 = 2,
FLAG3 = 4,
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QHash<stEvPairKey<int, unsigned long>, bool> m_hash;
m_hash.insert(stEvPairKey<int, unsigned long>(1, FLAG1 | FLAG3), true);
if(m_hash.contains(stEvPairKey<int, unsigned long>(1, FLAG1)))
qDebug()<<"FLAG1: true";
if(m_hash.contains(stEvPairKey<int, unsigned long>(1, FLAG1 | FLAG3)))
qDebug()<<"FLAG1 | FLAG3: true";
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks