mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Eat shit, std::tuple
This commit is contained in:
parent
1fc0d0882c
commit
2d14cedc17
|
@ -104,7 +104,7 @@ public:
|
|||
decltype(auto) call( Args&&... args ) {
|
||||
push();
|
||||
int pushcount = stack::multi_push( lua_state(), std::forward<Args>( args )... );
|
||||
return invoke( types<Ret...>( ), std::index_sequence_for<Ret...>(), pushcount );
|
||||
return invoke( types<Ret...>( ), std::make_index_sequence<sizeof...(Ret)>(), pushcount );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public:
|
|||
decltype(auto) call( Args&&... args ) const {
|
||||
push( );
|
||||
int pushcount = stack::multi_push( lua_state( ), std::forward<Args>( args )... );
|
||||
return invoke( types<Ret...>( ), std::index_sequence_for<Ret...>(), pushcount );
|
||||
return invoke( types<Ret...>( ), std::make_index_sequence<sizeof...(Ret)>(), pushcount );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ struct pusher<function_arguments<T, Args...>> {
|
|||
|
||||
template <typename FP>
|
||||
static int push(lua_State* L, FP&& fp) {
|
||||
return push_func(std::index_sequence_for<Args...>(), L, std::forward<FP>(fp));
|
||||
return push_func(std::make_index_sequence<sizeof...(Args)>(), L, std::forward<FP>(fp));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ inline int destruct(lua_State* L) {
|
|||
template <typename T, typename... Functions>
|
||||
struct usertype_constructor_function : base_function {
|
||||
typedef std::tuple<Functions...> overload_list;
|
||||
typedef std::index_sequence_for<Functions...> indices;
|
||||
typedef std::make_index_sequence<sizeof...(Functions)> indices;
|
||||
overload_list overloads;
|
||||
|
||||
usertype_constructor_function(overload_list set) : overloads(std::move(set)) {}
|
||||
|
|
|
@ -66,7 +66,7 @@ inline int overload_match_arity(types<Fx, Fxs...>, std::index_sequence<I, In...>
|
|||
|
||||
template <typename... Functions, typename Match, typename... Args>
|
||||
inline int overload_match_arity(Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) {
|
||||
return internals::overload_match_arity(types<Functions...>(), std::index_sequence_for<Functions...>(), std::index_sequence<>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
|
||||
return internals::overload_match_arity(types<Functions...>(), std::make_index_sequence<sizeof...(Functions)>(), std::index_sequence<>(), std::forward<Match>(matchfx), L, fxarity, start, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Functions, typename Match, typename... Args>
|
||||
|
@ -78,7 +78,7 @@ inline int overload_match(Match&& matchfx, lua_State* L, int start, Args&&... ar
|
|||
template <typename... Functions>
|
||||
struct overloaded_function : base_function {
|
||||
typedef std::tuple<Functions...> overload_list;
|
||||
typedef std::index_sequence_for<Functions...> indices;
|
||||
typedef std::make_index_sequence<sizeof...(Functions)> indices;
|
||||
overload_list overloads;
|
||||
|
||||
overloaded_function(overload_list set)
|
||||
|
@ -104,7 +104,7 @@ struct overloaded_function : base_function {
|
|||
template <typename T, typename... Functions>
|
||||
struct usertype_overloaded_function : base_function {
|
||||
typedef std::tuple<functor<T, std::remove_pointer_t<std::decay_t<Functions>>>...> overload_list;
|
||||
typedef std::index_sequence_for<Functions...> indices;
|
||||
typedef std::make_index_sequence<sizeof...(Functions)> indices;
|
||||
overload_list overloads;
|
||||
|
||||
usertype_overloaded_function(std::tuple<Functions...> set) : overloads(std::move(set)) {}
|
||||
|
|
|
@ -94,9 +94,6 @@ struct usertype_function : public usertype_function_core<Function, Tp> {
|
|||
|
||||
int prelude(lua_State* L) {
|
||||
this->fx.item = detail::ptr(stack::get<T>(L, 1));
|
||||
if(this->fx.item == nullptr) {
|
||||
return luaL_error(L, "sol: userdata for function call is null: are you using the wrong syntax? (use item:function/variable(...) syntax)");
|
||||
}
|
||||
return static_cast<base_t&>(*this)(meta::tuple_types<return_type>(), args_type(), Index<2>(), L);
|
||||
}
|
||||
|
||||
|
@ -119,9 +116,6 @@ struct usertype_variable_function : public usertype_function_core<Function, Tp>
|
|||
int prelude(lua_State* L) {
|
||||
int argcount = lua_gettop(L);
|
||||
this->fx.item = stack::get<T*>(L, 1);
|
||||
if(this->fx.item == nullptr) {
|
||||
return luaL_error(L, "sol: userdata for member variable is null");
|
||||
}
|
||||
switch(argcount) {
|
||||
case 2:
|
||||
return static_cast<base_t&>(*this)(meta::tuple_types<return_type>(), types<>(), Index<2>(), L);
|
||||
|
|
|
@ -154,7 +154,7 @@ public:
|
|||
handler h(error_handler);
|
||||
push();
|
||||
int pushcount = stack::multi_push(lua_state(), std::forward<Args>(args)...);
|
||||
return invoke(types<Ret...>(), std::index_sequence_for<Ret...>(), pushcount, h);
|
||||
return invoke(types<Ret...>(), std::make_index_sequence<sizeof...(Ret)>(), pushcount, h);
|
||||
}
|
||||
};
|
||||
} // sol
|
||||
|
|
|
@ -34,13 +34,19 @@ struct proxy_base {
|
|||
return super.template get<std::string>();
|
||||
}
|
||||
|
||||
template<typename T, meta::EnableIf<meta::Not<meta::is_string_constructible<T>>, is_proxy_primitive<meta::Unqualified<T>>> = 0>
|
||||
template <typename... Args>
|
||||
operator std::tuple<Args...>() const {
|
||||
const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
|
||||
return detail::forward_tuple(super.template get<std::tuple<Args...>>());
|
||||
}
|
||||
|
||||
template<typename T, meta::EnableIf<meta::Not<meta::is_specialization_of<meta::Unqualified<T>, std::tuple>>, meta::Not<meta::is_string_constructible<T>>, is_proxy_primitive<meta::Unqualified<T>>> = 0>
|
||||
operator T ( ) const {
|
||||
const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
|
||||
return super.template get<T>( );
|
||||
}
|
||||
|
||||
template<typename T, meta::EnableIf<meta::Not<meta::is_string_constructible<T>>, meta::Not<is_proxy_primitive<meta::Unqualified<T>>>> = 0>
|
||||
template<typename T, meta::EnableIf<meta::Not<meta::is_specialization_of<meta::Unqualified<T>, std::tuple>>, meta::Not<meta::is_string_constructible<T>>, meta::Not<is_proxy_primitive<meta::Unqualified<T>>>> = 0>
|
||||
operator T& ( ) const {
|
||||
const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
|
||||
return super.template get<T&>( );
|
||||
|
|
|
@ -273,7 +273,7 @@ struct checker<std::tuple<Args...>, type::poly, C> {
|
|||
|
||||
template <typename Handler>
|
||||
static bool check(lua_State* L, int index, Handler&& handler) {
|
||||
return apply(std::index_sequence_for<Args...>(), L, index, std::forward<Handler>(handler));
|
||||
return apply(std::make_index_sequence<sizeof...(Args)>(), L, index, std::forward<Handler>(handler));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -51,12 +51,12 @@ struct field_getter<std::tuple<Args...>, b, C> {
|
|||
|
||||
template <typename Keys>
|
||||
void get(lua_State* L, Keys&& keys) {
|
||||
apply(std::index_sequence_for<Args...>(), L, std::forward<Keys>(keys), lua_absindex(L, -1));
|
||||
apply(std::make_index_sequence<sizeof...(Args)>(), L, std::forward<Keys>(keys), lua_absindex(L, -1));
|
||||
}
|
||||
|
||||
template <typename Keys>
|
||||
void get(lua_State* L, Keys&& keys, int tableindex) {
|
||||
apply(std::index_sequence_for<Args...>(), L, std::forward<Keys>(keys), tableindex);
|
||||
apply(std::make_index_sequence<sizeof...(Args)>(), L, std::forward<Keys>(keys), tableindex);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ struct getter<std::tuple<Args...>> {
|
|||
}
|
||||
|
||||
static decltype(auto) get(lua_State* L, int index = -1) {
|
||||
return apply(std::index_sequence_for<Args...>(), L, index);
|
||||
return apply(std::make_index_sequence<sizeof...(Args)>(), L, index);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ public:
|
|||
decltype(auto) get( Keys&&... keys ) const {
|
||||
static_assert(sizeof...(Keys) == sizeof...(Ret), "number of keys and number of return types do not match");
|
||||
auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
|
||||
return tuple_get( types<Ret...>( ), std::index_sequence_for<Ret...>( ), std::forward_as_tuple(std::forward<Keys>(keys)...));
|
||||
return tuple_get( types<Ret...>( ), std::make_index_sequence<sizeof...(Ret)>( ), std::forward_as_tuple(std::forward<Keys>(keys)...));
|
||||
}
|
||||
|
||||
template<typename T, typename Key>
|
||||
|
|
|
@ -382,7 +382,7 @@ using is_c_str = Or<
|
|||
namespace meta_detail {
|
||||
template <typename T, meta::DisableIf<meta::is_specialization_of<meta::Unqualified<T>, std::tuple>> = 0>
|
||||
decltype(auto) force_tuple(T&& x) {
|
||||
return std::forward_as_tuple(x);
|
||||
return std::forward_as_tuple(std::forward<T>(x));
|
||||
}
|
||||
|
||||
template <typename T, meta::EnableIf<meta::is_specialization_of<meta::Unqualified<T>, std::tuple>> = 0>
|
||||
|
@ -393,7 +393,7 @@ decltype(auto) force_tuple(T&& x) {
|
|||
|
||||
template <typename... X>
|
||||
decltype(auto) tuplefy(X&&... x ) {
|
||||
return std::tuple_cat(meta_detail::force_tuple(x)...);
|
||||
return std::tuple_cat(meta_detail::force_tuple(std::forward<X>(x))...);
|
||||
}
|
||||
} // meta
|
||||
namespace detail {
|
||||
|
@ -402,6 +402,17 @@ decltype(auto) forward_get( Tuple&& tuple ) {
|
|||
return std::forward<meta::tuple_element_t<I, Tuple>>(std::get<I>(tuple));
|
||||
}
|
||||
|
||||
template <std::size_t... I, typename Tuple>
|
||||
auto forward_tuple_impl( std::index_sequence<I...>, Tuple&& tuple ) -> decltype(std::tuple<decltype(forward_get<I>(tuple))...>(forward_get<I>(tuple)...)) {
|
||||
return std::tuple<decltype(forward_get<I>(tuple))...>(std::move(std::get<I>(tuple))...);
|
||||
}
|
||||
|
||||
template <typename Tuple>
|
||||
auto forward_tuple( Tuple&& tuple ) {
|
||||
auto x = forward_tuple_impl(std::make_index_sequence<std::tuple_size<meta::Unqualified<Tuple>>::value>(), std::forward<Tuple>(tuple));
|
||||
return x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto unwrap(T&& item) -> decltype(std::forward<T>(item)) {
|
||||
return std::forward<T>(item);
|
||||
|
|
|
@ -31,7 +31,7 @@ using swallow = std::initializer_list<int>;
|
|||
} // detail
|
||||
|
||||
template<typename... Args>
|
||||
struct types { typedef std::index_sequence_for<Args...> indices; static constexpr std::size_t size() { return sizeof...(Args); } };
|
||||
struct types { typedef std::make_index_sequence<sizeof...(Args)> indices; static constexpr std::size_t size() { return sizeof...(Args); } };
|
||||
namespace meta {
|
||||
namespace detail {
|
||||
template<typename... Args>
|
||||
|
|
Loading…
Reference in New Issue
Block a user