title: C++ std::mem_fn and std::bind the other way around
body: <p>So I have been looking into using abstracted algorithms to reuse reoccurring patterns in my code. Specifically, I want to determine the the element in an array of nodes that has the highest 'score', determined by evaluation of a complex scoring member function.</p>
  
  <p>After <a href="https://stackoverflow.com/questions/58530330/c-no-raw-loops-without-losing-perfomance">some help</a> I've come up with (C++17)</p>
  
  <pre><code>template &lt;typename FwdIt, typename Eval, typename Pred = std::less&lt;&gt;&gt;
  constexpr FwdIt max_eval_element(FwdIt first, FwdIt last, Eval eval, Pred pred = Pred()) {
      FwdIt found = first;
      if (first != last) {
          auto best = eval(*found);
          while (++first != last) {
              if (auto const thisVal = eval(*first);
                  pred(best, thisVal)) {
                  found = first;
                  best = thisVal;
              }
          }
      }
      return found;
  }
  </code></pre>
  
  <p>So consider my Node class:</p>
  
  <pre><code>class Node {
  private:
      double val;
  public:
      Node(double val) noexcept : val(val) {}
  
      [[nodiscard]] auto Score1() const noexcept {
          return std::sqrt(std::log(10.0 / val));
      }
  
      [[nodiscard]] auto Score2(double other) const noexcept {
          return std::sqrt(std::log(other / val));
      }
  };
  </code></pre>
  
  <p>and my array of nodes:</p>
  
  <pre><code>std::array&lt;Node, 100000&gt; nodes;
  </code></pre>
  
  <p>I can call</p>
  
  <pre><code>auto const&amp; Node = *std::max_eval_element(std::cbegin(nodes), std::cend(nodes), std::mem_fn(&amp;Node::Score1));
  </code></pre>
  
  <p>but now I want to repeat this for <code>Score2</code>, where the input depends on some local variable... of course I can write some lambda function... but we have <code>std::bind</code> for that, right? I know you can cal bind on a member function like </p>
  
  <pre><code>std::bind(this, std::mem_fn(Node::Score1));
  </code></pre>
  
  <p>But what I want is the other way around. Which doesn't work.</p>
  
  <pre><code>auto const&amp; Node = *std::max_eval_element(std::cbegin(nodes), std::cend(nodes), std::bind(std::mem_fn(&amp;Node::Score2), 1.0));
  </code></pre>
  
  <p>I tried it the other way around, but that also doesn't work</p>
  
  <pre><code>auto const&amp; Node = *std::max_eval_element(std::cbegin(nodes), std::cend(nodes), std::mem_fn(std::bind(&amp;Node::Score2), 1.0));
  </code></pre>
  
  <p>I know <em>why</em> this doesn't work... a member function requires the object pointer as a (hidden) first argument. But that would mean we are missing something like <code>std::bind_mem_fn</code> or so... We had <code>std::bind2nd</code> in the past, but it has been removed in C++17...</p>
  
  <p>Again: of course I can use a lambda, but considering things like <code>std:mem_fn</code> and <code>std::bind</code> exist, and abstracted algorithms is a good thing...</p>
  
  <p>Am I missing something, Or is this just missing from the standard?</p>