title: Why would I want a .* operator in C++?
body: <p>I recently found out that the <code>.*</code> operator (and the closely related <code>-&gt;*</code> operator) exists in C++.  (See <a href="https://stackoverflow.com/questions/2548555/dot-asterisk-operator-in-c">this</a> question.)</p>
  
  <p>Seems neat at first, but why would I ever need such a thing?  The two answers in the linked question provided contrived examples which would benefit from a direct function call.</p>
  
  <p>Where a direct function call is inconvenient, a function object could be used instead, like the lambda functions that may be used in <code>std::sort</code>.  This removes a level of indirection and hence would be more performant than using <code>.*</code>.</p>
  
  <p>The linked question also mentioned a simplified version of this example:</p>
  
  <pre><code>struct A {
      int a;
      int b;
  };
  
  void set_member(A&amp; obj, int A::* ptr, int val){
      obj.*ptr = val;
  }
  
  int main()
  {
      A obj;
      set_member(obj, &amp;A::b, 5);
      set_member(obj, &amp;A::a, 7);
      // Both members of obj are now assigned
  }
  </code></pre>
  
  <p>But it's pretty trivial (perhaps even better practice because it's cleaner and isn't unnecessarily constrained to members of <code>A</code>) to do this instead:</p>
  
  <pre><code>struct A {
      int a;
      int b;
  };
  
  void set_me(int&amp; out, int val){
      out = val;
  }
  
  int main()
  {
      A obj;
      set_me(obj.b, 5);
      set_me(obj.a, 7);
      // Both members of obj are now assigned
  }
  </code></pre>
  
  <p>In conclusion, a pointer-to-member-function might be replaced by a function object, and a pointer-to-member-variable might be replaced by a direct reference of said variable or a function object.  Doing so might also increase the efficiency of the code due to one less indirection.</p>
  
  <p><a href="https://stackoverflow.com/questions/670734/c-pointer-to-class-data-member">This</a> question only provides examples where my conclusion stands, so <strong>it does not answer my question</strong>.</p>
  
  <p>Apart from interfacing legacy code which uses <code>.*</code> (in which there would be no choice at all), when, <em>really</em>, would I want to use <code>.*</code>?</p>