I was reading this wonderful interview with Alex Stepanov (the father of C++ STL) http://www.stlport.org/resources/StepanovUSA.html. It really worths the time, about the end of it, there is this question (emphasis mine):
Question:
A frequent dilemma for me was: should I design this function as a member function or as a generic (global) function? what has been the rationale of this decision in STL?Answer:
Make it global if it at all possible. It would be much nicer if begin and end were global – it would allow us to define them for C arrays. It would be so much nicer if operator* was global with the default definitions:
template <class T> T& operator*(T& x) { return x;}
template <class T> const T& operator*(const T& x) { return x;}
It would allow us to write:
copy(0, 25, ostream_iterator<int>("n"));
In general, for non-iterator objects operator* should return the object itself, the “meaning” of a non-naming thing is a thing itself. I would even love to write constructors and destructors as global functions. You could do some amazing stuff if this is allowed in the language.
The sentence in bold sparked my curiosity, I have tried to google it but the result set is full of intro C++ material if I am not specific enough and just the link to the interview if I am too specific.
Do you have any examples of “amazing stuff”? Is there any language that allowed it?
The interview is quite old, I was wondering if this specific topic has been explored more. If you point me in the right direction will be great.