title: Substitute for function wrappers
body: <p>I have a C++ class that manages two connections (source and target). Every operation on the connection is two phased, a prepare phase and a commit phase. Some of the operations I would like to do on both connections and using almost the same parameters.</p>
  
  <p>I.e.,</p>
  
  <pre><code>mngr::init_conn(int var1, int var2, int var3)
  {
      m_conn.prepare_init(source_id, var1, var2, var3);
      m_conn.commit();
  
      m_conn.prepare_init(target_id, var1, var2, var3);
      m_conn.commit();
  }
  
  mngr::update_conn(int var1, int var2)
  {
      m_conn.prepare_update(source_id, var1, var2);
      m_conn.commit();
  
      m_conn.prepare_update(target_id, var1, var2);
      m_conn.commit();
  }
  </code></pre>
  
  <p>Notice the same connection object manages both source and target connections. The connection object is not mine, and I am not allowed to change it.</p>
  
  <p>Is there a way to remove the code duplication inside the methods? I thought about wrapping the methods, but I was wondering if there is a way without generating a function wrapper for every function</p>
  
  <p>I thought about something like this:</p>
  
  <pre><code>mngr::init_wrapper(ID id,int var1, int var2, int var3)
  {
      m_conn.prepare_init(id, var1, var2, var3);
      m_conn.commit();
  }
  
  mngr::update_wrapper(ID id,int var1, int var2)
  {
      m_conn.prepare_update(id, var1, var2);
      m_conn.commit();
  }
  
  mngr::init_conn(int var1, int var2, int var3)
  {
      init_wrapper(source_id, var1, var2, var3);
      init_wrapper(target_id, var1, var2, var3);
  }
  
  mngr::update_conn(int var1, int var2)
  {
      update_wrapper(source_id, var1, var2);
      update_wrapper(target_id, var1, var2);
  }
  </code></pre>
  
  <p>Do you have ideas of ways not generating a function wrapper for every function?</p>