diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 21:34:00 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 21:34:00 +0900 |
commit | 6a9de91752dfe75e185bf90ab856367b2c804582 (patch) | |
tree | 2a12ecc84bf0055e317ef2e4aeec3439d92b2035 /lib/util.h | |
parent | d5397fe5ae2ca34d5cfb11394dac17728a2b50ce (diff) | |
parent | 5d1dd53890611376873f6f959e206d5a56cfff70 (diff) | |
download | libquotient-6a9de91752dfe75e185bf90ab856367b2c804582.tar.gz libquotient-6a9de91752dfe75e185bf90ab856367b2c804582.zip |
Merge branch 'kitsune-events-rewritten'
Diffstat (limited to 'lib/util.h')
-rw-r--r-- | lib/util.h | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -59,6 +59,42 @@ namespace QMatrixClient return std::unique_ptr<T1>(static_cast<T1*>(p.release())); } + /** Determine traits of an arbitrary function/lambda/functor + * This only works with arity of 1 (1-argument) for now but is extendable + * to other cases. Also, doesn't work with generic lambdas and function + * objects that have operator() overloaded + * \sa https://stackoverflow.com/questions/7943525/is-it-possible-to-figure-out-the-parameter-type-and-return-type-of-a-lambda#7943765 + */ + template <typename T> + struct function_traits : public function_traits<decltype(&T::operator())> + { }; // A generic function object that has (non-overloaded) operator() + + // Specialisation for a function + template <typename ReturnT, typename ArgT> + struct function_traits<ReturnT(ArgT)> + { + using return_type = ReturnT; + using arg_type = ArgT; + }; + + // Specialisation for a member function + template <typename ReturnT, typename ClassT, typename ArgT> + struct function_traits<ReturnT(ClassT::*)(ArgT)> + : function_traits<ReturnT(ArgT)> + { }; + + // Specialisation for a const member function + template <typename ReturnT, typename ClassT, typename ArgT> + struct function_traits<ReturnT(ClassT::*)(ArgT) const> + : function_traits<ReturnT(ArgT)> + { }; + + template <typename FnT> + using fn_return_t = typename function_traits<FnT>::return_type; + + template <typename FnT> + using fn_arg_t = typename function_traits<FnT>::arg_type; + #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) // Copy-pasted from Qt 5.10 template <typename T> @@ -68,6 +104,11 @@ namespace QMatrixClient static void qAsConst(const T &&) Q_DECL_EQ_DELETE; #endif + inline auto operator"" _ls(const char* s, std::size_t size) + { + return QLatin1String(s, int(size)); + } + /** An abstraction over a pair of iterators * This is a very basic range type over a container with iterators that * are at least ForwardIterators. Inspired by Ranges TS. |