In order to give functions the option to modify the vector I can\'t do
curr = myvec.at( i );
doThis( curr );
doThat( curr );
doStuffWith( curr );
Options that I see, in roughly inverse order of preference:
[]
instead of at()
.at()
once, and save it into a reference (see Kristo's answer above).Honestly, what you should do is play with the four different approaches, and just use the one that produces the easiest to understand code. In most cases we are happy to sacrifice a few machine cycles for code that is easier for human beings to maintain.