Radfler

::map_rank

May 25th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <map>
  2. #include <type_traits>
  3.  
  4. namespace details {
  5.  
  6.   template<typename T>
  7.   struct is_map : std::false_type { };
  8.  
  9.   template<typename Key, typename Value, typename Compare, typename Allocator>
  10.   struct is_map<std::map<Key, Value, Compare, Allocator>> : std::true_type { };
  11.  
  12.   template<std::size_t Value>
  13.   using constant = std::integral_constant<std::size_t, Value>;
  14.  
  15.   template<typename T, bool IsMap = is_map<T>::value>
  16.   struct map_rank {
  17.     using mapped_type = typename T::mapped_type;
  18.     using mapped_type_rank = typename map_rank<mapped_type>::type;
  19.     using type = constant<mapped_type_rank::value + 1>;
  20.   };
  21.  
  22.   template<typename T>
  23.   struct map_rank<T, false> {
  24.     using type = constant<0>;
  25.   };
  26.  
  27. }
  28.  
  29. template<typename Map>
  30. struct map_rank : details::map_rank<Map>::type { };
Add Comment
Please, Sign In to add comment