title: How to pass `boost::static_visitor` instances to functions
body: <p>I'm using <code>boost::variant</code> quite often in my projects. My colleagues now came up with the idea to pass around instances of specific <code>boost::static_visitor&lt;int&gt;</code> in order to customize the type of visitation. She had some code like the following:</p>
  
  <pre><code>#include &lt;boost/variant.hpp&gt;
  #include &lt;iostream&gt;
  
  typedef boost::variant&lt;int, std::string&gt; TVar;
  
  struct Visitor1 : public boost::static_visitor&lt;int&gt; {
      template&lt;typename T&gt; 
      result_type operator()(const T&amp;) {
          return 42;
      }
  };
  
  struct Visitor2 : public boost::static_visitor&lt;int&gt; {
      template&lt;typename T&gt;
      result_type operator()(const T&amp;) {
          return 21;
      }
  };
  
   int adder(const boost::static_visitor&lt;int&gt;&amp; visitor, const TVar&amp; visitable) {
       return visitable.apply_visitor(visitor) + 1;
   }
  
  int main(int argc, char **args) {
      Visitor1 v1;
      Visitor2 v2;
      TVar x;
  
      std::cout &lt;&lt; adder(v1, x) &lt;&lt; std::endl;
      std::cout &lt;&lt; adder(v2, x) &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>It looks perfectly sound to me, but it doesn't compile. My compiler says that <code>expression will not yield a function that takes one 1 argument</code> somewhere insider . </p>
  
  <p>What are we doing wrong?</p>