So I currently have some code similar to this:
(Note: not actual code, just pared down from a somewhat long and complex method for brevity.)
template<typename ArgT0, typename ArgT1, typename FuncT>
static void addMethod( const std::string& name, FuncT func )
{
Method script_func = [&]( const Arguments& args ) -> Value
{
func(UnsafeAnyCast<ArgT0>(args[0]),UnsafeAnyCast<ArgT1>(args[1]));
return Value::Undefined();
}
_prototype->Set( name, script_func );
}
It works fine in Visual Studio 2010, but I know that is far from any guarantee that it is standard compliant C++. Is there anything wrong with this as far as using the template arguments inside the lambda?
Yes, this is standard compliant: a lambda expression has access to all the visible names in its enclosing scope, it’s only variables that you need to capture
5.1.2 Lambda expressions [expr.prim.lambda]