summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-16 00:57:33 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-16 00:57:33 +0000
commit741a2f0638761d3058f8094f591fdc3c56c9ebf3 (patch)
tree4dedc0be70f8aa22f50158a4ecc36307376cbbf4
parentCreate GameState, the single global for the root of everything (diff)
downloadilt-741a2f0638761d3058f8094f591fdc3c56c9ebf3.tar.bz2
ilt-741a2f0638761d3058f8094f591fdc3c56c9ebf3.tar.xz
ilt-741a2f0638761d3058f8094f591fdc3c56c9ebf3.zip
Add requires on factory like functions
-rw-r--r--lib/collection.hpp2
-rw-r--r--lib/worker.h7
2 files changed, 4 insertions, 5 deletions
diff --git a/lib/collection.hpp b/lib/collection.hpp
index 1630fcc..cf51157 100644
--- a/lib/collection.hpp
+++ b/lib/collection.hpp
@@ -15,7 +15,7 @@ public:
template<typename T = Object, typename... Params>
auto
- create(Params &&... params)
+ create(Params &&... params) requires std::is_base_of_v<Object, T>
{
if constexpr (shared) {
auto obj = std::make_shared<T>(std::forward<Params>(params)...);
diff --git a/lib/worker.h b/lib/worker.h
index 04e351b..7df16cd 100644
--- a/lib/worker.h
+++ b/lib/worker.h
@@ -2,6 +2,7 @@
#define WORKER_H
#include <utility>
+class Work;
#if __cpp_lib_semaphore
# include <deque>
@@ -12,8 +13,6 @@
# include <thread>
# include <vector>
-class Work;
-
class Worker {
public:
Worker();
@@ -26,7 +25,7 @@ public:
template<typename T, typename... Params>
void
- addWork(Params &&... params)
+ addWork(Params &&... params) requires std::is_base_of_v<Work, T>
{
addWork(std::make_unique<T>(std::forward<Params>(params)...));
}
@@ -51,7 +50,7 @@ class Worker {
public:
template<typename T, typename... Params>
void
- addWork(Params &&... params)
+ addWork(Params &&... params) requires std::is_base_of_v<Work, T>
{
T(std::forward<Params>(params)...).doWork();
}