From 2d14cedc174880fcb2f4338fcf599d9483497e2e Mon Sep 17 00:00:00 2001 From: ThePhD Date: Thu, 31 Mar 2016 12:12:04 -0400 Subject: [PATCH] Eat shit, `std::tuple` --- sol/coroutine.hpp | 2 +- sol/function.hpp | 2 +- sol/function_types.hpp | 2 +- sol/function_types_allocator.hpp | 2 +- sol/function_types_overload.hpp | 6 +++--- sol/function_types_usertype.hpp | 6 ------ sol/protected_function.hpp | 2 +- sol/proxy_base.hpp | 10 ++++++++-- sol/stack_check.hpp | 2 +- sol/stack_field.hpp | 4 ++-- sol/stack_get.hpp | 2 +- sol/table_core.hpp | 2 +- sol/traits.hpp | 15 +++++++++++++-- sol/tuple.hpp | 2 +- 14 files changed, 35 insertions(+), 24 deletions(-) diff --git a/sol/coroutine.hpp b/sol/coroutine.hpp index af81c008..535194ac 100644 --- a/sol/coroutine.hpp +++ b/sol/coroutine.hpp @@ -104,7 +104,7 @@ public: decltype(auto) call( Args&&... args ) { push(); int pushcount = stack::multi_push( lua_state(), std::forward( args )... ); - return invoke( types( ), std::index_sequence_for(), pushcount ); + return invoke( types( ), std::make_index_sequence(), pushcount ); } }; } diff --git a/sol/function.hpp b/sol/function.hpp index 7e131622..2e67fb8e 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -81,7 +81,7 @@ public: decltype(auto) call( Args&&... args ) const { push( ); int pushcount = stack::multi_push( lua_state( ), std::forward( args )... ); - return invoke( types( ), std::index_sequence_for(), pushcount ); + return invoke( types( ), std::make_index_sequence(), pushcount ); } }; diff --git a/sol/function_types.hpp b/sol/function_types.hpp index ef2e13d0..4531381e 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -204,7 +204,7 @@ struct pusher> { template static int push(lua_State* L, FP&& fp) { - return push_func(std::index_sequence_for(), L, std::forward(fp)); + return push_func(std::make_index_sequence(), L, std::forward(fp)); } }; diff --git a/sol/function_types_allocator.hpp b/sol/function_types_allocator.hpp index c42de8bf..922197a0 100644 --- a/sol/function_types_allocator.hpp +++ b/sol/function_types_allocator.hpp @@ -94,7 +94,7 @@ inline int destruct(lua_State* L) { template struct usertype_constructor_function : base_function { typedef std::tuple overload_list; - typedef std::index_sequence_for indices; + typedef std::make_index_sequence indices; overload_list overloads; usertype_constructor_function(overload_list set) : overloads(std::move(set)) {} diff --git a/sol/function_types_overload.hpp b/sol/function_types_overload.hpp index 78c40e16..e3f73cc0 100644 --- a/sol/function_types_overload.hpp +++ b/sol/function_types_overload.hpp @@ -66,7 +66,7 @@ inline int overload_match_arity(types, std::index_sequence template inline int overload_match_arity(Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - return internals::overload_match_arity(types(), std::index_sequence_for(), std::index_sequence<>(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); + return internals::overload_match_arity(types(), std::make_index_sequence(), std::index_sequence<>(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); } template @@ -78,7 +78,7 @@ inline int overload_match(Match&& matchfx, lua_State* L, int start, Args&&... ar template struct overloaded_function : base_function { typedef std::tuple overload_list; - typedef std::index_sequence_for indices; + typedef std::make_index_sequence indices; overload_list overloads; overloaded_function(overload_list set) @@ -104,7 +104,7 @@ struct overloaded_function : base_function { template struct usertype_overloaded_function : base_function { typedef std::tuple>>...> overload_list; - typedef std::index_sequence_for indices; + typedef std::make_index_sequence indices; overload_list overloads; usertype_overloaded_function(std::tuple set) : overloads(std::move(set)) {} diff --git a/sol/function_types_usertype.hpp b/sol/function_types_usertype.hpp index 2a2d3baf..67c84508 100644 --- a/sol/function_types_usertype.hpp +++ b/sol/function_types_usertype.hpp @@ -94,9 +94,6 @@ struct usertype_function : public usertype_function_core { int prelude(lua_State* L) { this->fx.item = detail::ptr(stack::get(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(*this)(meta::tuple_types(), args_type(), Index<2>(), L); } @@ -119,9 +116,6 @@ struct usertype_variable_function : public usertype_function_core int prelude(lua_State* L) { int argcount = lua_gettop(L); this->fx.item = stack::get(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(*this)(meta::tuple_types(), types<>(), Index<2>(), L); diff --git a/sol/protected_function.hpp b/sol/protected_function.hpp index aeb8d940..eb3a1a15 100644 --- a/sol/protected_function.hpp +++ b/sol/protected_function.hpp @@ -154,7 +154,7 @@ public: handler h(error_handler); push(); int pushcount = stack::multi_push(lua_state(), std::forward(args)...); - return invoke(types(), std::index_sequence_for(), pushcount, h); + return invoke(types(), std::make_index_sequence(), pushcount, h); } }; } // sol diff --git a/sol/proxy_base.hpp b/sol/proxy_base.hpp index 037a27fc..8e274f5a 100644 --- a/sol/proxy_base.hpp +++ b/sol/proxy_base.hpp @@ -34,13 +34,19 @@ struct proxy_base { return super.template get(); } - template>, is_proxy_primitive>> = 0> + template + operator std::tuple() const { + const Super& super = *static_cast(static_cast(this)); + return detail::forward_tuple(super.template get>()); + } + + template, std::tuple>>, meta::Not>, is_proxy_primitive>> = 0> operator T ( ) const { const Super& super = *static_cast(static_cast(this)); return super.template get( ); } - template>, meta::Not>>> = 0> + template, std::tuple>>, meta::Not>, meta::Not>>> = 0> operator T& ( ) const { const Super& super = *static_cast(static_cast(this)); return super.template get( ); diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index eac0630a..8be8885a 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -273,7 +273,7 @@ struct checker, type::poly, C> { template static bool check(lua_State* L, int index, Handler&& handler) { - return apply(std::index_sequence_for(), L, index, std::forward(handler)); + return apply(std::make_index_sequence(), L, index, std::forward(handler)); } }; diff --git a/sol/stack_field.hpp b/sol/stack_field.hpp index add7df2b..f31ae354 100644 --- a/sol/stack_field.hpp +++ b/sol/stack_field.hpp @@ -51,12 +51,12 @@ struct field_getter, b, C> { template void get(lua_State* L, Keys&& keys) { - apply(std::index_sequence_for(), L, std::forward(keys), lua_absindex(L, -1)); + apply(std::make_index_sequence(), L, std::forward(keys), lua_absindex(L, -1)); } template void get(lua_State* L, Keys&& keys, int tableindex) { - apply(std::index_sequence_for(), L, std::forward(keys), tableindex); + apply(std::make_index_sequence(), L, std::forward(keys), tableindex); } }; diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index 5143f025..e2a0c95b 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -249,7 +249,7 @@ struct getter> { } static decltype(auto) get(lua_State* L, int index = -1) { - return apply(std::index_sequence_for(), L, index); + return apply(std::make_index_sequence(), L, index); } }; diff --git a/sol/table_core.hpp b/sol/table_core.hpp index bc95cacb..f5c11ec3 100644 --- a/sol/table_core.hpp +++ b/sol/table_core.hpp @@ -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::value>(*this); - return tuple_get( types( ), std::index_sequence_for( ), std::forward_as_tuple(std::forward(keys)...)); + return tuple_get( types( ), std::make_index_sequence( ), std::forward_as_tuple(std::forward(keys)...)); } template diff --git a/sol/traits.hpp b/sol/traits.hpp index 55a79ecb..4124df3a 100644 --- a/sol/traits.hpp +++ b/sol/traits.hpp @@ -382,7 +382,7 @@ using is_c_str = Or< namespace meta_detail { template , std::tuple>> = 0> decltype(auto) force_tuple(T&& x) { - return std::forward_as_tuple(x); + return std::forward_as_tuple(std::forward(x)); } template , std::tuple>> = 0> @@ -393,7 +393,7 @@ decltype(auto) force_tuple(T&& x) { template 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))...); } } // meta namespace detail { @@ -402,6 +402,17 @@ decltype(auto) forward_get( Tuple&& tuple ) { return std::forward>(std::get(tuple)); } +template +auto forward_tuple_impl( std::index_sequence, Tuple&& tuple ) -> decltype(std::tuple(tuple))...>(forward_get(tuple)...)) { + return std::tuple(tuple))...>(std::move(std::get(tuple))...); +} + +template +auto forward_tuple( Tuple&& tuple ) { + auto x = forward_tuple_impl(std::make_index_sequence>::value>(), std::forward(tuple)); + return x; +} + template auto unwrap(T&& item) -> decltype(std::forward(item)) { return std::forward(item); diff --git a/sol/tuple.hpp b/sol/tuple.hpp index 5f2db93e..e91c2599 100644 --- a/sol/tuple.hpp +++ b/sol/tuple.hpp @@ -31,7 +31,7 @@ using swallow = std::initializer_list; } // detail template -struct types { typedef std::index_sequence_for indices; static constexpr std::size_t size() { return sizeof...(Args); } }; +struct types { typedef std::make_index_sequence indices; static constexpr std::size_t size() { return sizeof...(Args); } }; namespace meta { namespace detail { template