title: C++ Function that takes an array, a predicate and a operator as arguments and apply the operator to array's element where predicate is satisfied
body: <p>I'm trying to write a function as described in title. 
  I made a template custom dynamic array called queue, and i need to create a function that checks for every element of this queue if a predicate passed by argument is satisfied; if it is, i need to apply an operator to that element also passed by argument. </p>
  
  <p>First of all I probably need an explanation.. the predicate should be unary so it could be something like "isdigit" or "isalpha", right? and as operator it could be something like a simple post-increment ++. 
  The main problem is that I really don't have any idea how can I pass operators and predicates as parameters in function. </p>
  
  <p>If I understood the request, here what I tried to do but of course is not working... anyone helping out?</p>
  
  <pre><code>template&lt;typename L, typename OPERATOR&gt;
  
  void change_if(queue&lt;L&gt; &amp;que, bool (*f)(L), OPERATOR op) {
  
      for(int i=0; i&lt;que._size-1; i++) {
          if ((*f)(que._queue[i]))
              que._queue[i] = op(que._queue[i]);
      }
  }
  
  int main(){
      //as constructor, 3 is referred to size of the queue and 99 to the values.
      queue&lt;int&gt; q(3, 99);
  
      change_if(q, isdigit, ++);
  
  }
  </code></pre>