Ignore:
Timestamp:
Apr 11, 2010, 1:05:12 AM (12 years ago)
Author:
Peter
Message:

closes #612

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/stl_utility.h

    r2220 r2239  
    499499
    500500
    501 
     501  /**
     502     Adaptor class that can be used to compare pointers, T*, when you
     503     want to compare them with respect to the objects they point to.
     504
     505     Example:
     506     \code
     507     std::vector<MyClass*> vec(18);
     508     ...
     509     PtrCompare<MyClass, std::greater<MyClass> > ptr_compare;
     510     std::sort(vec.begin(), vec.end(), ptr_compare);
     511     \endcode
     512
     513     The class Compare must be a <a
     514     href="http://www.sgi.com/tech/stl/BinaryFunction.html">binary
     515     functor</a> that takes two \c const \c T& and returns \c bool.
     516
     517     \since New in yat 0.7
     518   */
     519  template<typename T, class Compare = std::less<T> >
     520  class PtrCompare : std::binary_function<T const* const, T const* const, bool>
     521  {
     522  public:
     523    /**
     524       \brief Constructor.
     525
     526       Creates an instance of Compare using its default constructor.
     527     */
     528    PtrCompare(void)
     529    {
     530      BOOST_CONCEPT_ASSERT((boost::BinaryFunction<Compare, bool, const T&,
     531                            const T&>));
     532    }
     533
     534    /**
     535       \brief Constructor.
     536
     537       Creates a copy of \a c that will be used later.
     538     */
     539    PtrCompare(Compare c)
     540      : compare_(c)
     541    {
     542      BOOST_CONCEPT_ASSERT((boost::BinaryFunction<Compare, bool, const T&,
     543                            const T&>));
     544    }
     545
     546    /**
     547       \return true iff Compare(* \a lhs, * \a rhs ) is true.
     548     */
     549    bool operator()(T const* const lhs, T const* const rhs) const
     550    {
     551      return compare_(*lhs, *rhs);
     552    }
     553  private:
     554    Compare compare_;
     555
     556    // using compiler generated copy
     557    // PtrCompare(const PtrCompare&)
     558    // PtrCompare& operator=(const PtrCompare&)
     559  };
    502560
    503561  ///
Note: See TracChangeset for help on using the changeset viewer.