This commit is contained in:
ThePhD 2017-04-08 08:25:49 -04:00
parent 28fff10637
commit 814562260d
3 changed files with 40 additions and 4 deletions

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2017-04-07 01:10:42.173645 UTC
// This header was generated with sol v2.16.0 (revision e856abc)
// Generated 2017-04-08 12:25:20.970713 UTC
// This header was generated with sol v2.17.0 (revision 28fff10)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -11783,11 +11783,11 @@ namespace sol {
#endif
using std::begin;
auto it = begin(src);
--k;
if (k == src.size()) {
real_add_call_push(std::integral_constant<bool, detail::has_push_back<T>::value>(), L, src, 1);
return 0;
}
--k;
std::advance(it, k);
*it = stack::get<V>(L, 3);
return 0;

View File

@ -239,11 +239,11 @@ namespace sol {
#endif
using std::begin;
auto it = begin(src);
--k;
if (k == src.size()) {
real_add_call_push(std::integral_constant<bool, detail::has_push_back<T>::value>(), L, src, 1);
return 0;
}
--k;
std::advance(it, k);
*it = stack::get<V>(L, 3);
return 0;

View File

@ -522,3 +522,39 @@ end
REQUIRE(ct.x == 20);
}
}
TEST_CASE("containers/append-idiom", "ensure the append-idiom works as intended") {
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.script(
R"(
function f_fill(vec)
print("#vec in lua: " .. #vec)
for k = 1, #vec do
vec[k] = k
end
print("#vec in lua: " .. #vec)
end
function f_append(vec)
print("#vec in lua: " .. #vec)
vec[#vec] = -10456407
vec[#vec + 1] = -54
print("#vec in lua: " .. #vec)
end
)");
std::vector<int> fill_cmp{ 1, 2, 3 };
std::vector<int> append_cmp{ -1, -1, -10456407, -54 };
std::vector<int> vec1{ -1, -1, -1 };
std::vector<int> vec2{ -1, -1, -1 };
REQUIRE(vec1.size() == 3);
lua["f_fill"](vec1);
REQUIRE(vec1.size() == 3);
REQUIRE(vec1 == fill_cmp);
REQUIRE(vec2.size() == 3);
lua["f_append"](vec2);
REQUIRE(vec2.size() == 4);
REQUIRE(vec2 == append_cmp);
}