summaryrefslogtreecommitdiffstats
path: root/api/dead/src/TypeMagic.h
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-04-10 17:01:24 +0200
committerPetr Mrázek <peterix@gmail.com>2016-05-01 00:00:24 +0200
commit1be7d573326570d63e55e36235537ed2b1831ae1 (patch)
treeba7037671cde8688e87e69acb753df80ec4cd4f9 /api/dead/src/TypeMagic.h
parentaa4842a91d35481264ae5a7c0ac17ea43610b600 (diff)
downloadMultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.gz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.lz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.xz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.zip
NOISSUE re/move some dead code and unused build system parts
Diffstat (limited to 'api/dead/src/TypeMagic.h')
-rw-r--r--api/dead/src/TypeMagic.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/api/dead/src/TypeMagic.h b/api/dead/src/TypeMagic.h
new file mode 100644
index 00000000..fa9d12a9
--- /dev/null
+++ b/api/dead/src/TypeMagic.h
@@ -0,0 +1,37 @@
+#pragma once
+
+namespace TypeMagic
+{
+/** "Cleans" the given type T by stripping references (&) and cv-qualifiers (const, volatile) from it
+ * const int => int
+ * QString & => QString
+ * const unsigned long long & => unsigned long long
+ *
+ * Usage:
+ * using Cleaned = Detail::CleanType<const int>;
+ * static_assert(std::is_same<Cleaned, int>, "Cleaned == int");
+ */
+// the order of remove_cv and remove_reference matters!
+template <typename T>
+using CleanType = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
+
+/// For functors (structs with operator()), including lambdas, which in **most** cases are functors
+/// "Calls" Function<Ret(*)(Arg)> or Function<Ret(C::*)(Arg)>
+template <typename T> struct Function : public Function<decltype(&T::operator())> {};
+/// For function pointers (&function), including static members (&Class::member)
+template <typename Ret, typename Arg> struct Function<Ret(*)(Arg)> : public Function<Ret(Arg)> {};
+/// Default specialization used by others.
+template <typename Ret, typename Arg> struct Function<Ret(Arg)>
+{
+ using ReturnType = Ret;
+ using Argument = Arg;
+};
+/// For member functions. Also used by the lambda overload if the lambda captures [this]
+template <class C, typename Ret, typename Arg> struct Function<Ret(C::*)(Arg)> : public Function<Ret(Arg)> {};
+template <class C, typename Ret, typename Arg> struct Function<Ret(C::*)(Arg) const> : public Function<Ret(Arg)> {};
+/// Overload for references
+template <typename F> struct Function<F&> : public Function<F> {};
+/// Overload for rvalues
+template <typename F> struct Function<F&&> : public Function<F> {};
+// for more info: https://functionalcpp.wordpress.com/2013/08/05/function-traits/
+}