is_key_container_of.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_TYPE_TRAITS_IS_KEY_CONTAINER_OF_HPP_JOFA_100829
  9. #define BOOST_ICL_TYPE_TRAITS_IS_KEY_CONTAINER_OF_HPP_JOFA_100829
  10. #include <boost/mpl/has_xxx.hpp>
  11. #include <boost/icl/type_traits/is_combinable.hpp>
  12. #include <boost/icl/type_traits/is_container.hpp>
  13. namespace boost{ namespace icl
  14. {
  15. //--------------------------------------------------------------------------
  16. namespace detail
  17. {
  18. BOOST_MPL_HAS_XXX_TRAIT_DEF(key_object_type)
  19. }
  20. //--------------------------------------------------------------------------
  21. template <class Type>
  22. struct has_key_object_type
  23. : mpl::bool_<detail::has_key_object_type<Type>::value>
  24. {};
  25. template <class Type, bool HasKeyContainerType, bool IsSet>
  26. struct get_key_object_type;
  27. template <class Type>
  28. struct get_key_object_type<Type, false, false>
  29. {
  30. typedef Type no_type;
  31. };
  32. template <class Type>
  33. struct get_key_object_type<Type, false, true>
  34. {
  35. typedef Type type;
  36. };
  37. template <class Type, bool IsSet>
  38. struct get_key_object_type<Type, true, IsSet>
  39. {
  40. typedef typename Type::key_object_type type;
  41. };
  42. template <class Type>
  43. struct key_container_type_of
  44. {
  45. typedef typename
  46. get_key_object_type
  47. < Type
  48. , has_key_object_type<Type>::value
  49. , mpl::or_<is_set<Type>, is_map<Type> >::value
  50. >::type type;
  51. };
  52. //--------------------------------------------------------------------------
  53. template<class KeyT, class ObjectT>
  54. struct is_strict_key_container_of // set is_strict_key_container_of map
  55. {
  56. typedef is_strict_key_container_of<KeyT, ObjectT> type;
  57. BOOST_STATIC_CONSTANT(bool, value =
  58. (mpl::and_< is_map<ObjectT>
  59. , boost::is_same<KeyT, typename key_container_type_of<ObjectT>::type> >::value)
  60. );
  61. };
  62. template<class KeyT, class ObjectT>
  63. struct is_key_container_of // set is_key_container_of (set or map)
  64. {
  65. typedef is_key_container_of<KeyT, ObjectT> type;
  66. BOOST_STATIC_CONSTANT(bool, value =
  67. (mpl::or_< is_strict_key_container_of<KeyT, ObjectT>
  68. , mpl::and_< mpl::or_<is_set<ObjectT>, is_map<ObjectT> >
  69. , boost::is_same<ObjectT, KeyT> > >::value)
  70. );
  71. };
  72. }} // namespace boost icl
  73. #endif