Nice, but the example crashes because you take a reference to uninitialized vector, if you initialize it and grow the vector I found that it will either keep "working fine" if you don't expect the data to change or randomly give garbage data - depending on compiler/stdlib - especially since the time when the buffer grows is implementation defined.
On VC++ it will return :
Reference is 0 but value is 9
On clang it will return :
Reference is 32579632 but value is 9
So let's say I wasn't mutating the 0 index, VC example would work fine at runtime and then clang would suddenly start giving garbage results. This has caused me week of debugging in a big code base.
Here is a better example : http://rextester.com/MAJDQ8375
On VC++ it will return : Reference is 0 but value is 9
On clang it will return : Reference is 32579632 but value is 9
So let's say I wasn't mutating the 0 index, VC example would work fine at runtime and then clang would suddenly start giving garbage results. This has caused me week of debugging in a big code base.