Sfoglia il codice sorgente

Add support for iterating over map types

Sam Jaffe 4 anni fa
parent
commit
724dd7f406
2 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 2 0
      include/cli/cli.h
  2. 6 0
      include/cli/types.h

+ 2 - 0
include/cli/cli.h

@@ -90,6 +90,8 @@ template <typename T> void cli_print(T const & value) {
     for (auto & elem : value) {
       cli_print(elem);
     }
+  } else if constexpr (detail::is_map_value_type_v<T>) {
+    std::cout << "  " << value.first << ": " << value.second << "\n";
   } else {
     std::cout << "  " << value << "\n";
   }

+ 6 - 0
include/cli/types.h

@@ -13,8 +13,14 @@ template <typename T, typename = void> struct is_container : std::false_type {};
 template <typename T>
 struct is_container<T, std::enable_if_t<!std::is_void_v<typename T::value_type>>> : std::true_type {};
 
+template <typename T, typename = void> struct is_map_value_type : std::false_type {};
+template <typename K, typename V>
+struct is_map_value_type<std::pair<K const, V>> : std::true_type {};
+
 template <typename T>
 static constexpr bool const is_string_v = is_string<T>::value;
 template <typename T>
 static constexpr bool const is_container_v = is_container<T>::value;
+template <typename T>
+static constexpr bool const is_map_value_type_v = is_map_value_type<T>::value;
 }