#line 344 "/home/travis/build/felix-lang/felix/src/packages/pointers.fdoc"
  
  Utility class to leverage STL sort.
  class Sort
  {
    STL compliant comparator object built from
    a closure of a Felix function.
    private header stl_comparator_def =
    """
    template<class CT, class FT2, class FFT>
    struct comparator {
      FFT cmp;
      comparator() : cmp(0) {}
      comparator(FFT cmp_a) : cmp(cmp_a) {}
      bool operator ()(CT x, CT y){
        ::std::pair<CT,CT> z(x,y);
        return cmp->apply(*(FT2*)(void*)&z);
      }
    };
    """ requires Cxx_headers::utility;
  
    private type _comparator[CT,FT2,FFT] = "comparator<?1,?2,?3>" requires stl_comparator_def;
    type stl_comparator[T] = new _comparator[T,T*T,T*T->bool];
  
    private fun _make_comparator[CT,FT2,FFT]: FFT -> stl_comparator[CT] =
      "comparator<?1,?2,?3>($1)"
    ;
  
    Make a C++ STL comparator object from a Felix comparison function.
    ctor[T] stl_comparator[T] (cmp:T * T -> bool) =>
      _make_comparator[T, T*T, T*T->bool] (cmp)
    ;
  
    Invoke stl sort with C++ comparator.
    proc stl_sort[T]: stl_comparator[T] * +T * +T = "::std::sort($2, $3, $1);"
      requires Cxx_headers::algorithm;
  
    Invoke stl sort with Felix comparison function.
    inline proc stl_sort[T] (cmp: T * T -> bool, b: +T,  e:+T) =>
      stl_sort (stl_comparator cmp, b, e)
    ;
  
    Invoke stl sort default comparison function.
    inline proc stl_sort[T with Tord[T]] (b:+T, e:+T) => stl_sort ( (< of (T * T)), b, e);
  
  }