Re:Better C – A subset of D Programming Language
by lumberjackstian on Tuesday April 28, 2020 @04:20PM
(#23011425)
Yeah I realise I could've explained a bit more about template arguments indeed! The point was that it can be hard to specify the return type.
I agree with your point, but for the sake of the audience who doesn't know D I think this example is misleading, as one could take the "int i" parameter as a runtime one, while it's actually a compile time one (the equivalent of C++ non-type template parameter). If you instantiate the function with 0 as a compile-time parameter, it is a function that returns int; otherwise it's a function that returns string. It is never a function that can return int or string.