title: private static member function or free function in anonymous namespace?
body: <p>I've recently made a change stylistically and wanted to see how other c++ programmers felt about it and if there were any downsides to it.</p>
  
  <p>Essentially, when I needed a utility function which doesn't need access to a given class member, what I used to do was something like this:</p>
  
  <p><strong>file.h</strong></p>
  
  <pre><code>class A {
  public:
      // public interface
  private:
      static int some_function(int);
  };
  </code></pre>
  
  <p><strong>file.cpp</strong></p>
  
  <pre><code>int A::some_function(int) {
      // ...
  }
  </code></pre>
  
  <p>But more recently, I have been preferring to do something more like this:</p>
  
  <p><strong>file.cpp</strong></p>
  
  <pre><code>namespace {
      int some_function(int) {
  
      }
  }
  // the rest of file.cpp
  </code></pre>
  
  <p>Here's my thought process:</p>
  
  <ul>
  <li>it's one less file the edit</li>
  <li>simply having the function be listed in the header file can hint at implementation details
  which have no need to be exposed (even if not publically available).</li>
  <li>if the prototype of the function needs to change, only one file needs to be recompiled.</li>
  </ul>
  
  <p>The last one is the most compelling to me. So my question is: <strong>are there any downsides to this?</strong></p>
  
  <p>They are functionally equivalent for most purposes that I can think of. It kind of seems to me that a <code>private static</code> function can almost always be converted to a free function in an anonymous <code>namespace</code>.</p>
  
  <p><strong>EDIT</strong>: One thing that comes to mind is that a <code>private static</code> function would have access to <code>private</code> members if given a pointer to an object to operate on, but if that's the case, why not make it a non-<code>static</code> member?</p>
  
  <p>What do you guys think?</p>