title: Pass an unary predicate to a function in C++
body: <p>I need a function which establishes a policy for my class for displaying items. e.g:</p>
  
  <pre><code>SetDisplayPolicy(BOOLEAN_PRED_T f)
  </code></pre>
  
  <p>This is assuming BOOLEAN_PRED_T is a <strong>function-pointer</strong> to some boolean predicate type like:</p>
  
  <pre><code>typedef bool (*BOOLEAN_PRED_T) (int);
  </code></pre>
  
  <p>I'm interested only on e.g: display something when the passed predicate is TRUE, do not display when it's false.</p>
  
  <p>The above example works for functions returning bool and taking an int, but I need a very generic pointer for the SetDisplayPolicy argument, so I thought of UnaryPredicate, but it's boost related. How I can pass a unary predicate to a function in STL/C++? <code>unary_function&lt; bool,T &gt;</code> won't work because I need a bool as return value, but I want to ask the user just for "unary function that returns bool", in the most generic approach.</p>
  
  <p>I thought of deriving my own type as:</p>
  
  <pre><code>template&lt;typename T&gt;
  class MyOwnPredicate : public std::unary_function&lt;bool, T&gt;{};
  </code></pre>
  
  <p>Could that be a good approach?</p>