How to generate C++ function automatically?
<p>I want to write a c++ matrix operation code, some operation are the same for some function. I wonder whether there are some method to merge them? For example:</p>

<pre><code>void add1(vector&lt;vector&lt;double&gt; &gt; &amp;m){
    for(int i = 0; i &lt; m.size(); ++i){
        for(int j = 0; j &lt; m[i].size(); ++j){
            m[i][j] += 1.0;
        }
    }
}

void minus1(vector&lt;vector&lt;double&gt; &gt; &amp;m){
    for(int i = 0; i &lt; m.size(); ++i){
        for(int j = 0; j &lt; m[i].size(); ++j){
            m[i][j] -= 1.0;
        }
    }
}
</code></pre>

<p>The two pieces of code is almost the same. How can I avoid to rewrite it for two times? Are there something like template that can generate code automatically?</p>