/************************************************************************************ * * * Copyright (c) 2014 - 2018 Axel Menzel * * * * This file is part of RTTR (Run Time Type Reflection) * * License: MIT License * * * * Permission is hereby granted, free of charge, to any person obtaining * * a copy of this software and associated documentation files (the "Software"), * * to deal in the Software without restriction, including without limitation * * the rights to use, copy, modify, merge, publish, distribute, sublicense, * * and/or sell copies of the Software, and to permit persons to whom the * * Software is furnished to do so, subject to the following conditions: * * * * The above copyright notice and this permission notice shall be included in * * all copies or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * * SOFTWARE. * * * *************************************************************************************/ #ifndef RTTR_FUNCTION_TRAITS_H_ #define RTTR_FUNCTION_TRAITS_H_ #include "rttr/detail/base/core_prerequisites.h" #include "rttr/detail/misc/misc_type_traits.h" #include "rttr/detail/misc/std_type_traits.h" #include #include #include namespace rttr { namespace detail { ///////////////////////////////////////////////////////////////////////////////////// template struct is_function_ptr : std::integral_constant::value && std::is_function<::rttr::detail::remove_pointer_t>::value> { }; ///////////////////////////////////////////////////////////////////////////////////// // snippet provided by K-ballo struct helper { void operator()(...); }; template struct helper_composed: T, helper {}; template struct member_function_holder {}; template > struct is_functor_impl : std::true_type {}; template struct is_functor_impl::operator()> > : std::false_type {}; /*! * \brief Returns true whether the given type T is a functor. * i.e. func(...); That can be free function, lambdas or function objects. */ template struct is_functor : conditional_t::value, is_functor_impl, std::false_type> {}; template struct is_functor : std::true_type {}; template struct is_functor : std::true_type {}; #ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE template struct is_functor : std::true_type {}; template struct is_functor : std::true_type {}; #endif ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// template struct function_traits : function_traits< decltype(&T::operator()) > {}; template struct function_traits { static RTTR_CONSTEXPR_OR_CONST size_t arg_count = sizeof...(Args); using return_type = R; using arg_types = std::tuple; }; template struct function_traits : function_traits { }; template struct function_traits : function_traits { }; template struct function_traits : function_traits { using class_type = C; }; template struct function_traits : function_traits { using class_type = C; }; template struct function_traits : function_traits { using class_type = C; }; template struct function_traits : function_traits {using class_type = C; }; #ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE template struct function_traits : function_traits { }; template struct function_traits : function_traits { }; template struct function_traits : function_traits { using class_type = C; }; template struct function_traits : function_traits { using class_type = C; }; template struct function_traits : function_traits { using class_type = C; }; template struct function_traits : function_traits {using class_type = C; }; #endif template struct function_traits> : function_traits {}; ///////////////////////////////////////////////////////////////////////////////////// // use it like e.g: // param_types::type template struct param_types { using type = typename std::tuple_element::arg_types>::type; }; template using param_types_t = typename param_types::type; ///////////////////////////////////////////////////////////////////////////////////// template struct is_void_func : conditional_t< std::is_same::return_type, void>::value, std::true_type, std::false_type > { }; ///////////////////////////////////////////////////////////////////////////////////// // returns an std::true_type, when the given type F is a function type; otherwise an std::false_type. template using is_function = std::integral_constant::value || std::is_function::value || is_functor::value >; ///////////////////////////////////////////////////////////////////////////////////// } // end namespace detail } // end namespace rttr #endif // RTTR_FUNCTION_TRAITS_H_