/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 as published by the Free Software ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ****************************************************************************/ #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