QModelIndex: add constexpr

The functions dealing with the void* internalPointer() can't be
constexpr on GCC 4.6 and Clang 3.2-trunk, even though GCC 4.8-trunk
accepts it, because of the casts required.

Change-Id: Id04105312da3d0c7632f7df06a34bc5a71120b32
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Marc Mutz 2012-02-24 17:41:31 +01:00 committed by The Qt Project
parent 3291e0a77c
commit d16efdfc0e

View File

@ -59,24 +59,24 @@ class Q_CORE_EXPORT QModelIndex
{ {
friend class QAbstractItemModel; friend class QAbstractItemModel;
public: public:
inline QModelIndex() : r(-1), c(-1), i(0), m(0) {} Q_DECL_CONSTEXPR inline QModelIndex() : r(-1), c(-1), i(0), m(0) {}
// compiler-generated copy/move ctors/assignment operators are fine! // compiler-generated copy/move ctors/assignment operators are fine!
inline int row() const { return r; } Q_DECL_CONSTEXPR inline int row() const { return r; }
inline int column() const { return c; } Q_DECL_CONSTEXPR inline int column() const { return c; }
inline quintptr internalId() const { return i; } Q_DECL_CONSTEXPR inline quintptr internalId() const { return i; }
inline void *internalPointer() const { return reinterpret_cast<void*>(i); } inline void *internalPointer() const { return reinterpret_cast<void*>(i); }
inline QModelIndex parent() const; inline QModelIndex parent() const;
inline QModelIndex sibling(int row, int column) const; inline QModelIndex sibling(int row, int column) const;
inline QModelIndex child(int row, int column) const; inline QModelIndex child(int row, int column) const;
inline QVariant data(int role = Qt::DisplayRole) const; inline QVariant data(int role = Qt::DisplayRole) const;
inline Qt::ItemFlags flags() const; inline Qt::ItemFlags flags() const;
inline const QAbstractItemModel *model() const { return m; } Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const { return m; }
inline bool isValid() const { return (r >= 0) && (c >= 0) && (m != 0); } Q_DECL_CONSTEXPR inline bool isValid() const { return (r >= 0) && (c >= 0) && (m != 0); }
inline bool operator==(const QModelIndex &other) const Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const
{ return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); } { return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); }
inline bool operator!=(const QModelIndex &other) const Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const
{ return !(*this == other); } { return !(*this == other); }
inline bool operator<(const QModelIndex &other) const Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const
{ {
return r < other.r return r < other.r
|| (r == other.r && (c < other.c || (r == other.r && (c < other.c
@ -86,7 +86,7 @@ public:
private: private:
inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel)
: r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {} : r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {}
inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel)
: r(arow), c(acolumn), i(id), m(amodel) {} : r(arow), c(acolumn), i(id), m(amodel) {}
int r, c; int r, c;
quintptr i; quintptr i;