procedureControl (F : accessprocedure) isbegin
F.all;
end Control;
voidcontrol(void (*f)()) {
(*f)();
}
T control(Func<T> f) {
return f();
}
import std.traits;
void control(alias f)()
if (isCallable!f)
{
f();
}
The alias parameter allow to pass whatever you want as template parameter. For more safety a constraint tests if the argument is something that can be run.
void control(voidfunction() f)
{
f();
}
The standard, C-like, solution that uses a functionpointer as run-time parameter and not a template one.
control(Function f) => f();
defcontrol(f) do
f()
end
module x
implicitnonecontainssubroutine control(f)
interfacesubroutine f()
endsubroutine f
endinterfacecall f
endsubroutine control
endmodule x
funccontrol(f func()) {
f()
}
Go supports first class functions, higher-order functions, user-defined function types, function literals, and closures.
module x
implicit none
contains
subroutine control(f)
interface
subroutine f()
end subroutine f
end interface
call f
end subroutine control
end module x