Witam
Trochę już siedzę w C++, ale mam kilka pytań odnoście takich zagrań:
template<typename R, typename... T>
R LuaObject::callLuaField(const std::string& field, const T&... args) {
R result;
int rets = luaCallField(field, args...);
if(rets > 0) {
assert(rets == 1);
result = g_lua.polymorphicPop<R>();
} else
result = R();
return result;
}
Jeśli zrobiłem takie coś, to jak mogę później w funkcji CallField jakoś ogarnąć te argumenty, np. zrobić z nich pętle lub coś takiego.
Druga sprawa, tutaj znalazłem taki kod:
template<typename C, typename... Args>
std::function<void(const std::shared_ptr<C>&, const Args&...)> make_mem_func(void (C::* f)(Args...)) {
auto mf = std::mem_fn(f);
return [=](const std::shared_ptr<C>& obj, const Args&... args) mutable -> void {
if(!obj)
throw LuaException("failed to call a member function because the passed object is nil");
mf(obj.get(), args...);
};
}
I nie wiem jak działa dokładnie to:
return [=](const std::shared_ptr<C>& obj, const Args&... args) mutable -> void {
if(!obj)
throw LuaException("failed to call a member function because the passed object is nil");
mf(obj.get(), args...);
};
Znaczy domyślam się, że to chyba funkcja anyomous (czy jakoś tak), która występuje w C#. Dobrze mówię, czy to nie to? Jeśli tak, to może ktoś mi to przybliżyć lub dać jakiś link?
Dzięki, to wszystko pozdrawiam