I'm trying to create a way to store information where the most recent data has a greater influence. This what I have thought of so far. I stopped at 5, but it goes on and on, is there an easier/more efficient way to program this information?
are you asking about AI/sensor/etc decision algorithms, eg
sum = current *.75 + last *.10 + old *.05
...
if (sum > threshold) //threshold might be a sigmoid or something
... this is a 'weighted' approach where the current is worth a lot more than the previous value which is worth more than the value 2 iterations ago... a common technique if the data is numerical or can be treated as such...
another way is pure choice...
if current vs last does not make sense
use last
else use current (you can nest this to check against several historical values as needed, 2-3 is usual)
this is useful for like sensor/streamed data, where you occasionally get a glitch, so if you had
100 110 115 500000 ... you can ignore the 500000 value as a glitch and revert to 115 for an iteration...
does either of these make sense for what you are doing??
you probably don't ever want to do this rotating copy logic like your snippet shows.
a circular buffer is a good approach for this type of data, this is a very easy to write data structure that can be written on top of a vector very easily. If you are asking how to avoid all that copying, this is what you asked. If you want to understand how to weight stuff, the above may be useful.