modify_key_adaptor.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright 2003-2013 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_MODIFY_KEY_ADAPTOR_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_MODIFY_KEY_ADAPTOR_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. namespace boost{
  14. namespace multi_index{
  15. namespace detail{
  16. /* Functional adaptor to resolve modify_key as a call to modify.
  17. * Preferred over compose_f_gx and stuff cause it eliminates problems
  18. * with references to references, dealing with function pointers, etc.
  19. */
  20. template<typename Fun,typename Value,typename KeyFromValue>
  21. struct modify_key_adaptor
  22. {
  23. modify_key_adaptor(Fun f_,KeyFromValue kfv_):f(f_),kfv(kfv_){}
  24. void operator()(Value& x)
  25. {
  26. f(kfv(x));
  27. }
  28. private:
  29. Fun f;
  30. KeyFromValue kfv;
  31. };
  32. } /* namespace multi_index::detail */
  33. } /* namespace multi_index */
  34. } /* namespace boost */
  35. #endif