From 1e51b62c882b5fc1554efb46cb41c3d54157626c Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 6 Jun 2015 12:30:49 +0200 Subject: NOISSUE Comment and bugfix the Resource system --- logic/TypeMagic.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 logic/TypeMagic.h (limited to 'logic/TypeMagic.h') diff --git a/logic/TypeMagic.h b/logic/TypeMagic.h new file mode 100644 index 00000000..fa9d12a9 --- /dev/null +++ b/logic/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; + * static_assert(std::is_same, "Cleaned == int"); + */ +// the order of remove_cv and remove_reference matters! +template +using CleanType = typename std::remove_cv::type>::type; + +/// For functors (structs with operator()), including lambdas, which in **most** cases are functors +/// "Calls" Function or Function +template struct Function : public Function {}; +/// For function pointers (&function), including static members (&Class::member) +template struct Function : public Function {}; +/// Default specialization used by others. +template struct Function +{ + using ReturnType = Ret; + using Argument = Arg; +}; +/// For member functions. Also used by the lambda overload if the lambda captures [this] +template struct Function : public Function {}; +template struct Function : public Function {}; +/// Overload for references +template struct Function : public Function {}; +/// Overload for rvalues +template struct Function : public Function {}; +// for more info: https://functionalcpp.wordpress.com/2013/08/05/function-traits/ +} -- cgit v1.2.3