aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-28 19:45:21 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:54 +0200
commitf0883534b3303cf2b74f3ab51efe16615d2561a9 (patch)
treec1dfb0d47afb60a6117234431fe6b457e42e6ae5
parent522c446c801e62d360480744a6e89d91dd840c95 (diff)
refactor: move is_func to own type traits file
-rw-r--r--src/DI/container.hpp16
-rw-r--r--src/DI/type_traits.hpp16
2 files changed, 19 insertions, 13 deletions
diff --git a/src/DI/container.hpp b/src/DI/container.hpp
index 6cb89ce..2dd194f 100644
--- a/src/DI/container.hpp
+++ b/src/DI/container.hpp
@@ -1,9 +1,9 @@
#pragma once
+#include "DI/interfaces/wrapper.hpp"
#include "DI/object_type.hpp"
-#include "interfaces/wrapper.hpp"
+#include "DI/type_traits.hpp"
-#include <functional>
#include <memory>
#include <type_traits>
#include <unordered_map>
@@ -26,16 +26,6 @@ private:
Container *_container;
};
-template <typename Satan>
-struct is_func : public std::false_type // NOLINT(readability-identifier-naming)
-{
-};
-
-template <typename Satan, typename... Args>
-struct is_func<std::function<Satan(Args...)>> : public std::true_type
-{
-};
-
class Container
{
public:
@@ -47,7 +37,7 @@ public:
template <class Interface, class = std::enable_if_t<std::is_abstract_v<Interface>>>
std::shared_ptr<Interface> get() const;
- template <typename Interface, typename = std::enable_if_t<is_func<Interface>::value>>
+ template <typename Interface, typename = std::enable_if_t<is_func_v<Interface>>>
Interface get() const;
std::unordered_map<BaseObjectType, std::shared_ptr<IGenericWrapper>, ObjectTypeHasher>
diff --git a/src/DI/type_traits.hpp b/src/DI/type_traits.hpp
new file mode 100644
index 0000000..a852a4f
--- /dev/null
+++ b/src/DI/type_traits.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <functional>
+
+template <typename NotAFunc>
+struct is_func : public std::false_type // NOLINT(readability-identifier-naming)
+{
+};
+
+template <typename Return, typename... Args>
+struct is_func<std::function<Return(Args...)>> : public std::true_type
+{
+};
+
+template <typename PossiblyFunc>
+inline constexpr bool is_func_v = is_func<PossiblyFunc>::value;