There are comparatively many storage class specifiers for functions arguments in D, which are:
- none
in
(which is equivalent toconst scope
)out
ref
scope
lazy
const
immutable
shared
inout
What's the rational behind them? Their names already put forth the obvious use. However, there are some open questions:
- Should I use
ref
combined within
forstruct
type function arguments by default? - Does
out
implyref
implicitely? - When should I use none?
- Does
ref
on classes and/or interfaces make sense? (Class types are references by default.) - How about
ref
on array slices? - Should I use
const
for built-in arithmetic types, whenever possible?
More generally put: When and why should I use which storage class specifier for function argument types in case of built-in types, arrays, structs, classes and interfaces?
(In order to isolate the scope of the question a little bit, please don't discuss shared
, since it has its own isolated meaning.)