Algol (1958) is the spiritual parent language of the C/C++/C#/Java family. It introduced the accursed "int x" syntax which Niklaus Wirth tried to undo with Pascal and other designs. Yet the notation persists and perpetures a 60-year confusion around types and values.
int f(int) {return 3;} is shorthand for f(0)=3, f(1)=3, f(2)=3, .. with each integer substituting into that "int" placeholder. Whereas array is a compile-time function from types to types, and array<int> produces the type of arrays of integers.
-
-
In the later case, array<int> is just a type and isn't shorthand for something like array<0>, array<1>, array<2>, .. as substituting placeholders implies.
-
It is already the substitute, thing you substituted was the T in the template. If you want the functionality o/t mentioned function then write a function, otherwise you want a container where you can put stuff. How would you get a container where you could put ints in otherwise?
- 1 more reply
New conversation -
-
-
That function definition would be illegal in C (though legal in C++). If f is a function of type "int (int)" and "int f(int x) {return 3;}" is a legal definition for such a function in C, then only the latter contains a placeholder and that placeholder is "x," not "int."
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.