// Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include namespace Utils { /* struct functionTraits { using ResultType; // Return type of Function struct argument { using type; // type of Function argument at index (starting with 0) } } struct functionTakesArgument; Is derived from std::true_type if Function takes an argument of type ArgumentType at index. Otherwise derived from std::false_type. */ //////////////////// // functionTraits //////////////////// // for callables. defined below. template struct functionTraits; // function template struct functionTraits { using ResultType = Result; static const unsigned arity = sizeof...(Args); // TODO const -> constexpr with MSVC2015 template struct argument { using type = typename std::tuple_element>::type; }; }; // function pointer template struct functionTraits : public functionTraits { }; // const function pointer template struct functionTraits : public functionTraits { }; // member function template struct functionTraits : public functionTraits { }; // const member function template struct functionTraits : public functionTraits { }; // const pointer to member function template struct functionTraits : public functionTraits { }; // const pointer to const member function template struct functionTraits : public functionTraits { }; // TODO: enable lvalue and rvalue ref member function later (MSVC 2015?) //// lvalue ref member function //template //struct functionTraits : public functionTraits //{ //}; //// const lvalue ref member function //template //struct functionTraits : public functionTraits //{ //}; //// rvalue ref member function //template //struct functionTraits : public functionTraits //{ //}; // callables. only works if operator() is not overloaded. template struct functionTraits { using callableTraits = functionTraits; using ResultType = typename callableTraits::ResultType; static const unsigned arity = callableTraits::arity - 1; // ignore object pointer arg // TODO const -> constexpr with MSVC2015 template struct argument { using type = typename callableTraits::template argument::type; // ignore object pointer arg }; }; // lvalue ref callables template struct functionTraits : public functionTraits { }; // const lvalue ref callables template struct functionTraits : public functionTraits { }; // rvalue ref callables template struct functionTraits : public functionTraits { }; template using functionResult_t = typename functionTraits::ResultType; //////////////////// // functionTakesArgument //////////////////// namespace Internal { template struct functionTakesArgumentArityDispatch; template struct functionTakesArgumentArityDispatch : public std::false_type { }; template struct functionTakesArgumentArityDispatch : public std::is_same::template argument::type> { }; } // Internal template struct functionTakesArgument : public Internal::functionTakesArgumentArityDispatch< std::integral_constant::arity > index)>, Function, index, T> { }; } // Utils