title: "Rule of thumb" for free function vs member function
body: <p>There is a popular guideline (Scott Meyers, Klaus Iglberger, ect) that I recently put more thought into, which is basically <strong><em>prefer non-member (free) functions to member functions.</em></strong> I'm noticing that I can indeed actually pull most of my member functions outside, but I'm having a hard time figuring out when that's actually <em>what I should do</em>.</p>
  
  <p>Here is a simple example, a function that prints a vector of strings (a private data member) to console in some formatted way:</p>
  
  <pre><code>void list::print() const {
      std::cout &lt;&lt; "Printing list -&gt; " &lt;&lt; list_.size() &lt;&lt; " entries.\n";
      std::cout &lt;&lt; "--- START OF LIST ---\n";
      for (const auto &amp;s : list_) {
          std::cout &lt;&lt; s.size() &lt;&lt; " : " &lt;&lt; s &lt;&lt; '\n';
      }
      std::cout &lt;&lt; "--- END OF LIST ---\n";
  }
  </code></pre>
  
  <p>I find it difficult to decide in simple cases like this, it seems to me that in the short term the member function is a bit more elegant whilst a free function can adapt to multiple objects as a program gets larger. Does anyone have some kind of rule of thumb to help decide? Am I just overthinking this? Thanks.</p>