Passing in a functor to a functor
<p>I'm trying to write a functor that I can pass to std::sort that will sort a vector representing the indicies for another vector of objects based on the comparison of the objects in the vector.  Rather than assume that the objects in the vector have a member operator&lt;, I want to pass in a predicate such as I would pass into std::sort if I was sorting the vector of objects directly. </p>

<pre><code>template &lt;class T, class _Pr&gt;
class SortIndexVectorObjectsHelper : public std::binary_function&lt;ULONG, ULONG, bool&gt;
{
    ULONG m_ulSize;
    std::vector&lt;T&gt; &amp; m_aItems;
    BOOL m_bSortAscending;
    _Pr m_Comp;

public:

    SortIndexVectorObjectsHelper(std::vector&lt;T&gt; &amp; aItems, _Pr Comp) : m_aItems(aItems), m_Comp(Comp), m_ulSize(0)
    {
        m_ulSize = m_aItems.size();
    }

    bool operator()( ULONG &amp; rLeft, ULONG &amp; rRight) 
    {
        if (rLeft &lt; m_ulSize &amp;&amp; rRight &lt; m_ulSize)
        {
            T &amp; pLeft = m_aItems[rLeft];
            T &amp; pRight = m_aItems[rRight];

            if (pLeft &amp;&amp; pRight)
            {
                return m_Comp(pLeft, pRight);
            }
        }
        return false;
    }


};

struct SortFooByX: public std::binary_function&lt;CFoo,CFoo, bool&gt;
{
    BOOL m_bSortAscending;

    SortFooByX(BOOL bSortAscending)
    {
        m_bSortAscending = bSortAscending;
    }

    bool operator()( CFoo &amp; _Left,  CFoo &amp; _Right) 
    {

         if (m_bSortAscending)
         {
        if (_Left.X() &lt; _Right.X())
           return true;
         }
         else
         {
        if (_Left.X() &gt; _Right.X()) 
                   return true;

          }

          return false;
    }


};

std::sort(aFooIndicies.begin(), aFooIndicies.end(), SortIndexVectorObjectsHelper&lt;CFoo, std::binary_function&lt;CFoo, CFoo, bool&gt; &gt;(aFoo, SortFooByX(FALSE)));
</code></pre>

<p>Compiling this gives me the error that none of the 2 overloads could convert all of the argument types.</p>
