Fix error in Reverse function.
This commit is contained in:
parent
9389cb546c
commit
dc14f164be
|
@ -31,6 +31,7 @@
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
class QPointF;
|
class QPointF;
|
||||||
|
|
||||||
|
@ -183,14 +184,13 @@ inline void Move(T &vector, int from, int to)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T Reverse(const T &container)
|
QVector<T> Reverse(const QVector<T> &container)
|
||||||
{
|
{
|
||||||
if (container.isEmpty())
|
if (container.isEmpty())
|
||||||
{
|
{
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
T reversed;
|
QVector<T> reversed(container.size());
|
||||||
reversed.reserve(container.size());
|
|
||||||
qint32 j = 0;
|
qint32 j = 0;
|
||||||
for (qint32 i = container.size() - 1; i >= 0; --i)
|
for (qint32 i = container.size() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
|
@ -200,6 +200,20 @@ T Reverse(const T &container)
|
||||||
return reversed;
|
return reversed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, template <typename> class C>
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
C<T> Reverse(const C<T> &container)
|
||||||
|
{
|
||||||
|
return ConvertToList(Reverse(ConvertToVector(container)));
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T, typename std::enable_if<std::is_same<T, QStringList>::value, T>::type* = nullptr>
|
||||||
|
T Reverse(const T &container)
|
||||||
|
{
|
||||||
|
return Reverse<QString, QList>(container);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename Cont, typename Input>
|
template <typename Cont, typename Input>
|
||||||
inline void AppendTo(Cont &container, const Input &input)
|
inline void AppendTo(Cont &container, const Input &input)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user