From 49094115b1f179fd07e9cc5a9504215b7a2c33d2 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 8 May 2016 20:03:54 +0200 Subject: [PATCH] static assert as discussed here https://dev.vatsim-germany.org/issues/648#note-10 #648 --- src/blackgui/models/listmodeldbobjects.cpp | 6 +++++- src/blackmisc/datastoreobjectlist.cpp | 7 ++++++- src/blackmisc/orderablelist.cpp | 5 ++++- src/blackmisc/timestampobjectlist.cpp | 5 ++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/blackgui/models/listmodeldbobjects.cpp b/src/blackgui/models/listmodeldbobjects.cpp index b028dac98..7a509d6fd 100644 --- a/src/blackgui/models/listmodeldbobjects.cpp +++ b/src/blackgui/models/listmodeldbobjects.cpp @@ -9,6 +9,8 @@ #include "listmodeldbobjects.h" #include "allmodelcontainers.h" +#include "blackmisc/datastoreobjectlist.h" +#include using namespace BlackMisc; using namespace BlackMisc::Aviation; @@ -21,7 +23,9 @@ namespace BlackGui CListModelDbObjects::CListModelDbObjects(const QString &translationContext, QObject *parent) : CListModelBase(translationContext, parent) { - // void + constexpr bool hasIntegerKey = std::is_base_of::value && std::is_same::value; + constexpr bool hasStringKey = std::is_base_of::value && std::is_base_of::value; + static_assert(hasIntegerKey || hasStringKey, "ObjectType needs to implement IDatastoreObjectWithXXXXKey and have appropriate KeyType"); } template diff --git a/src/blackmisc/datastoreobjectlist.cpp b/src/blackmisc/datastoreobjectlist.cpp index 365703dc2..ab6a2920a 100644 --- a/src/blackmisc/datastoreobjectlist.cpp +++ b/src/blackmisc/datastoreobjectlist.cpp @@ -17,12 +17,17 @@ #include "blackmisc/simulation/distributorlist.h" #include #include +#include namespace BlackMisc { template IDatastoreObjectList::IDatastoreObjectList() - { } + { + constexpr bool hasIntegerKey = std::is_base_of::value && std::is_same::value; + constexpr bool hasStringKey = std::is_base_of::value && std::is_base_of::value; + static_assert(hasIntegerKey || hasStringKey, "ObjectType needs to implement IDatastoreObjectWithXXXXKey and have appropriate KeyType"); + } template OBJ IDatastoreObjectList::findByKey(KEYTYPE key, const OBJ ¬Found) const diff --git a/src/blackmisc/orderablelist.cpp b/src/blackmisc/orderablelist.cpp index d988ff796..7263994c3 100644 --- a/src/blackmisc/orderablelist.cpp +++ b/src/blackmisc/orderablelist.cpp @@ -12,12 +12,15 @@ #include "blackmisc/simulation/aircraftmodellist.h" #include #include +#include namespace BlackMisc { template IOrderableList::IOrderableList() - { } + { + static_assert(std::is_base_of::value, "OBJ needs to implement IOrderable"); + } template const CONTAINER &IOrderableList::container() const diff --git a/src/blackmisc/timestampobjectlist.cpp b/src/blackmisc/timestampobjectlist.cpp index fbf60f3c6..44200bf10 100644 --- a/src/blackmisc/timestampobjectlist.cpp +++ b/src/blackmisc/timestampobjectlist.cpp @@ -22,12 +22,15 @@ #include "blackmisc/countrylist.h" #include #include +#include namespace BlackMisc { template ITimestampObjectList::ITimestampObjectList() - { } + { + static_assert(std::is_base_of::value, "OBJ needs to implement ITimestampBased"); + } template const CONTAINER &ITimestampObjectList::container() const