mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
I wish C++ didn't demand that functions have to appear before each other in lexographic order. =/
This commit is contained in:
parent
b90f789986
commit
ef223ecaeb
|
@ -26,29 +26,6 @@
|
|||
#include <type_traits>
|
||||
|
||||
namespace sol {
|
||||
namespace detail {
|
||||
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
|
||||
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> { };
|
||||
|
||||
template<typename T>
|
||||
struct is_function_impl<T, true> {
|
||||
using yes = char;
|
||||
using no = struct { char s[ 2 ]; };
|
||||
|
||||
struct F { void operator()( ); };
|
||||
struct Derived : T, F { };
|
||||
template<typename U, U> struct Check;
|
||||
|
||||
template<typename V>
|
||||
static no test( Check<void ( F::* )( ), &V::operator()>* );
|
||||
|
||||
template<typename>
|
||||
static yes test( ... );
|
||||
|
||||
static const bool value = sizeof( test<Derived>( 0 ) ) == sizeof( yes );
|
||||
};
|
||||
} // detail
|
||||
|
||||
template<typename T, typename R = void>
|
||||
using EnableIf = typename std::enable_if<T::value, R>::type;
|
||||
|
||||
|
@ -78,6 +55,30 @@ struct multi_return<> : types<>{
|
|||
|
||||
template<bool B>
|
||||
using Bool = std::integral_constant<bool, B>;
|
||||
|
||||
namespace detail {
|
||||
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
|
||||
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> { };
|
||||
|
||||
template<typename T>
|
||||
struct is_function_impl<T, true> {
|
||||
using yes = char;
|
||||
using no = struct { char s[ 2 ]; };
|
||||
|
||||
struct F { void operator()( ); };
|
||||
struct Derived : T, F { };
|
||||
template<typename U, U> struct Check;
|
||||
|
||||
template<typename V>
|
||||
static no test( Check<void ( F::* )( ), &V::operator()>* );
|
||||
|
||||
template<typename>
|
||||
static yes test( ... );
|
||||
|
||||
static const bool value = sizeof( test<Derived>( 0 ) ) == sizeof( yes );
|
||||
};
|
||||
} // detail
|
||||
|
||||
template<typename T>
|
||||
struct Function : Bool<detail::is_function_impl<T>::value> { };
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user