// sol2 // The MIT License (MIT) // Copyright (c) 2013-2022 Rapptz, ThePhD and contributors // 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 SOL_BIND_TRAITS_HPP #define SOL_BIND_TRAITS_HPP #include #include #include namespace sol { namespace meta { namespace meta_detail { template using detect_deducible_signature = decltype(&F::operator()); } // namespace meta_detail template using call_operator_deducible = typename is_detected::type; template constexpr inline bool call_operator_deducible_v = call_operator_deducible::value; namespace meta_detail { template struct void_tuple_element : meta::tuple_element { }; template struct void_tuple_element> { typedef void type; }; template using void_tuple_element_t = typename void_tuple_element::type; template struct basic_traits { private: using first_type = meta::conditional_t::value, int, T>&; public: inline static constexpr const bool is_noexcept = it_is_noexcept; inline static constexpr bool is_member_function = std::is_void::value; inline static constexpr bool has_c_var_arg = has_c_variadic; inline static constexpr std::size_t arity = sizeof...(Args); inline static constexpr std::size_t free_arity = sizeof...(Args) + static_cast(!std::is_void::value); typedef types args_list; typedef std::tuple args_tuple; typedef T object_type; typedef R return_type; typedef tuple_types returns_list; typedef R(function_type)(Args...); typedef meta::conditional_t::value, args_list, types> free_args_list; typedef meta::conditional_t::value, R(Args...), R(first_type, Args...)> free_function_type; typedef meta::conditional_t::value, R (*)(Args...), R (*)(first_type, Args...)> free_function_pointer_type; typedef std::remove_pointer_t signature_type; template using arg_at = void_tuple_element_t; }; template ::value> struct fx_traits : public basic_traits { }; // Free Functions template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args...); }; template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args...); }; template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args..., ...); }; template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args..., ...); }; // Member Functions /* C-Style Variadics */ template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...); }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...); }; /* Const Volatile */ template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile; }; /* Member Function Qualifiers */ template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) &; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) &; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) &&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) &&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const&&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const&&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile&&; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&; }; #if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE) template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args...) noexcept; }; template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args...) noexcept; }; template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args..., ...) noexcept; }; template struct fx_traits : public basic_traits { typedef R (*function_pointer_type)(Args..., ...) noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) noexcept; }; /* Const Volatile */ template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) & noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) & noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const& noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const& noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile& noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile& noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) && noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) && noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const&& noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const&& noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile&& noexcept; }; template struct fx_traits : public basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile&& noexcept; }; #endif // noexcept is part of a function's type #if SOL_IS_ON(SOL_COMPILER_VCXX) && SOL_IS_ON(SOL_PLATFORM_X86) template struct fx_traits : public basic_traits { typedef R(__stdcall* function_pointer_type)(Args...); }; template struct fx_traits : public basic_traits { typedef R(__stdcall* function_pointer_type)(Args...); }; template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...); }; /* Const Volatile */ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const; }; template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile; }; /* Member Function Qualifiers */ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) &; }; template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const&; }; template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&; }; template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) &&; }; template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const&&; }; template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&; }; #if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE) template struct fx_traits : public basic_traits { typedef R(__stdcall* function_pointer_type)(Args...) noexcept; }; template struct fx_traits : public basic_traits { typedef R(__stdcall* function_pointer_type)(Args...) noexcept; }; /* __stdcall cannot be applied to functions with varargs*/ /*template struct fx_traits<__stdcall R(Args..., ...) noexcept, false> : public basic_traits { typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; }; template struct fx_traits : public basic_traits { typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) noexcept; };*/ /* Const Volatile */ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) & noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) & noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const& noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile& noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) && noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) && noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const&& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const&& noexcept; };*/ template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : public basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile&& noexcept; };*/ #endif // noexcept is part of a function's type #endif // __stdcall x86 VC++ bug template struct fx_traits : public fx_traits::function_type, false> { }; template ::value> struct callable_traits : public fx_traits> { }; template struct callable_traits { typedef meta::conditional_t, std::add_lvalue_reference_t, R> return_type; typedef return_type Arg; typedef T object_type; using signature_type = R(T::*); inline static constexpr bool is_noexcept = false; inline static constexpr bool is_member_function = false; inline static constexpr std::size_t arity = 1; inline static constexpr std::size_t free_arity = 2; typedef std::tuple args_tuple; typedef types args_list; typedef types free_args_list; typedef meta::tuple_types returns_list; typedef return_type(function_type)(T&, return_type); typedef return_type (*function_pointer_type)(T&, Arg); typedef return_type (*free_function_pointer_type)(T&, Arg); template using arg_at = void_tuple_element_t; }; } // namespace meta_detail template using bind_traits = meta_detail::callable_traits; namespace meta_detail { template struct is_probably_stateless_lambda : std::false_type { }; template struct is_probably_stateless_lambda : std::is_convertible::function_type*>::type { }; } // namespace meta_detail template using is_probably_stateless_lambda = typename meta_detail::is_probably_stateless_lambda && call_operator_deducible_v>::type; template inline constexpr bool is_probably_stateless_lambda_v = is_probably_stateless_lambda::value; template using function_args_t = typename bind_traits::args_list; template using function_signature_t = typename bind_traits::signature_type; template using function_return_t = typename bind_traits::return_type; }} // namespace sol::meta #endif // SOL_BIND_TRAITS_HPP