value_compare.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright 2003-2008 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_VALUE_COMPARE_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_VALUE_COMPARE_HPP
  10. #if defined(_MSC_VER)&&(_MSC_VER>=1200)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/call_traits.hpp>
  15. #include <functional>
  16. namespace boost{
  17. namespace multi_index{
  18. namespace detail{
  19. template<typename Value,typename KeyFromValue,typename Compare>
  20. struct value_comparison:std::binary_function<Value,Value,bool>
  21. {
  22. value_comparison(
  23. const KeyFromValue& key_=KeyFromValue(),const Compare& comp_=Compare()):
  24. key(key_),comp(comp_)
  25. {
  26. }
  27. bool operator()(
  28. typename call_traits<Value>::param_type x,
  29. typename call_traits<Value>::param_type y)const
  30. {
  31. return comp(key(x),key(y));
  32. }
  33. private:
  34. KeyFromValue key;
  35. Compare comp;
  36. };
  37. } /* namespace multi_index::detail */
  38. } /* namespace multi_index */
  39. } /* namespace boost */
  40. #endif