In C++ you can use the class
std::valarray
. It is similar to
std::vector
, but defines a number of standard operators that modify each element individually. check out
http://www.cplusplus.com/reference/valarray/valarray/operators/[
^] as a reference; it also includes some example code.
For incrementing an array you could write e. g.:
#include <valarray> // std::valarray
void foo ()
{
int myarray[]= {10,20,30,40};
std::valarray<int> bar (myarray, 4);
bar += 1; }
P.S.:
A word of warning if you use this class in Windows: some standard windows header file
#defines
the macros
min()
and
max()
, which will nuke the functions
std::valarray::min()
and
std::valarray::max()
if included before you include
valarray
. You can prevent this in various manners:
1. use
#undef
to kill these definitions
2. use
#define NOMINMAX
before including the windows headers to prevent their definition
3.
#include
valarray
first
(Just one of the many reasons why I hate
#define
!)