1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(core): fix IndexedList comparison type casts from signed/unsigned

This commit is contained in:
Nils Fenner 2016-07-31 20:22:05 +02:00
parent 6c150a04c0
commit 9f8ad3cf77
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C

View File

@ -11,24 +11,37 @@ public:
explicit IndexedList() = default;
// Qt
bool isEmpty()
inline bool isEmpty()
{
return v.empty();
}
bool contains(int i)
template <typename cmp_type>
bool contains(cmp_type i)
{
return std::find_if(begin(), end(), [i](T& t){return (int)t == i;}) != end();
return std::find_if(begin(), end(), [i](T& t)
{
return static_cast<cmp_type>(t) == i;
}) != end();
}
void remove(int i)
template <typename cmp_type>
void remove(cmp_type i)
{
v.erase(std::remove_if(begin(), end(), [i](T& t){return (int)t == i;}), end());
v.erase(std::remove_if(begin(), end(), [i](T& t)
{
return static_cast<cmp_type>(t) == i;
}), end());
}
T &operator[](int i)
template <typename cmp_type>
T& operator[](cmp_type i)
{
iterator it = std::find_if(begin(), end(), [i](T& t){return (int)t == i;});
iterator it = std::find_if(begin(), end(), [i](T& t)
{
return static_cast<cmp_type>(t) == i;
});
if (it == end())
it = insert({});
@ -44,34 +57,32 @@ public:
{
return v.begin();
}
inline const_iterator begin() const
{
return v.begin();
}
inline const_iterator cbegin() const
{
return v.cbegin();
}
inline iterator end()
{
return v.end();
}
inline const_iterator end() const
{
return v.end();
}
inline const_iterator cend() const
{
return v.cend();
}
inline iterator erase(iterator pos)
{
return v.erase(pos);
}
inline iterator erase(iterator first, iterator last)
{
return v.erase(first, last);
}
inline iterator insert(T&& value)
{
v.push_back(std::move(value));