Pārlūkot izejas kodu

Move type inspectors to own file.

Sam Jaffe 5 gadi atpakaļ
vecāks
revīzija
22f362cb50
2 mainītis faili ar 22 papildinājumiem un 18 dzēšanām
  1. 2 18
      include/cli/cli.h
  2. 20 0
      include/cli/types.h

+ 2 - 18
include/cli/cli.h

@@ -16,26 +16,10 @@
 #include <vector>
 
 #include "lambda_cast.h"
+#include "types.h"
 
 namespace cli {
 
-template <typename T> struct is_string : std::false_type {};
-template <typename T>
-struct is_string<T*> : std::is_same<std::remove_cv_t<T>, char> {};
-template <typename T>
-struct is_string<T[]> : std::is_same<std::remove_cv_t<T>, char> {};
-template <typename...Ts>
-struct is_string<std::basic_string<Ts...>> : std::true_type {};
-
-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>
-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;
-
 class cli {
 public:
   using args_t = std::vector<std::string>;
@@ -101,7 +85,7 @@ cli & cli::register_callback(std::string const & handle,
 }
 
 template <typename T> void cli_print(T const & value) {
-  if constexpr (is_container_v<T> && !is_string_v<T>) {
+  if constexpr (detail::is_container_v<T> && !detail::is_string_v<T>) {
     using ::cli::cli_print;
     for (auto & elem : value) {
       cli_print(elem);

+ 20 - 0
include/cli/types.h

@@ -0,0 +1,20 @@
+#pragma once
+
+namespace cli::detail {
+template <typename T> struct is_string : std::false_type {};
+template <typename T>
+struct is_string<T*> : std::is_same<std::remove_cv_t<T>, char> {};
+template <typename T>
+struct is_string<T[]> : std::is_same<std::remove_cv_t<T>, char> {};
+template <typename...Ts>
+struct is_string<std::basic_string<Ts...>> : std::true_type {};
+
+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>
+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;
+}