map_value.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2010-2010: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_CONCEPT_MAP_VALUE_HPP_JOFA_100924
  9. #define BOOST_ICL_CONCEPT_MAP_VALUE_HPP_JOFA_100924
  10. #include <boost/icl/type_traits/predicate.hpp>
  11. #include <boost/icl/type_traits/identity_element.hpp>
  12. #include <boost/icl/type_traits/is_map.hpp>
  13. namespace boost{ namespace icl
  14. {
  15. //==============================================================================
  16. //= AlgoUnifiers<Map>
  17. //==============================================================================
  18. template<class Type, class Iterator>
  19. inline typename enable_if<is_map<Type>, const typename Type::key_type>::type&
  20. key_value(Iterator it_)
  21. {
  22. return (*it_).first;
  23. }
  24. template<class Type, class Iterator>
  25. inline typename enable_if<is_map<Type>, const typename Type::codomain_type>::type&
  26. co_value(Iterator it_)
  27. {
  28. return (*it_).second;
  29. }
  30. template<class Type>
  31. inline typename enable_if<is_map<Type>, typename Type::value_type>::type
  32. make_value(const typename Type:: key_type& key_val,
  33. const typename Type::codomain_type& co_val)
  34. {
  35. return typename Type::value_type(key_val, co_val);
  36. }
  37. template <class Type>
  38. class content_is_identity_element: public property<Type>
  39. {
  40. public:
  41. bool operator() (const Type& value_pair)const
  42. {
  43. return value_pair.second
  44. == identity_element<typename Type::second_type>::value();
  45. }
  46. } ;
  47. }} // namespace boost icl
  48. #endif