From b6d455a02bd338e9dc0faa09d4d8177ecd8d569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 10 Apr 2016 15:53:05 +0200 Subject: NOISSUE reorganize and document libraries --- api/logic/TypeMagic.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 api/logic/TypeMagic.h (limited to 'api/logic/TypeMagic.h') diff --git a/api/logic/TypeMagic.h b/api/logic/TypeMagic.h new file mode 100644 index 00000000..fa9d12a9 --- /dev/null +++ b/api/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