From 117549bf70d801a59e341a1f5610b987f3edd7f9 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 5 May 2018 11:36:47 +0900 Subject: [PATCH] change is_(map|container) and remove needless trait --- toml/traits.hpp | 9 -------- toml/value.hpp | 57 +++++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/toml/traits.hpp b/toml/traits.hpp index 5e6e425..f6d5c38 100644 --- a/toml/traits.hpp +++ b/toml/traits.hpp @@ -58,15 +58,6 @@ struct has_resize_method : decltype(has_resize_method_impl::check(nullptr)){} #undef decltype(...) #endif -template -struct is_container : std::integral_constant::value && has_value_type::value>{}; - -template -struct is_map : std::integral_constant::value && has_key_type::value && - has_mapped_type::value>{}; - }// detail }//toml #endif // TOML_TRAITS diff --git a/toml/value.hpp b/toml/value.hpp index d773c24..e918393 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -99,33 +99,6 @@ constexpr inline bool is_valid(value_t vt) return vt != value_t::Unknown; } -template struct is_toml_array : std::false_type{}; -template<> struct is_toml_array : std::true_type {}; -template struct is_toml_table : std::false_type{}; -template<> struct is_toml_table : std::true_type {}; - -struct is_key_convertible_impl -{ - template - static std::is_convertible - check(typename T::key_type*); - - template static std::false_type check(...); -}; - -/// Intel C++ compiler can not use decltype in parent class declaration, here -/// is a hack to work around it. https://stackoverflow.com/a/23953090/4692076 -#ifdef __INTEL_COMPILER -#define decltype(...) std::enable_if::type -#endif - -template -struct is_key_convertible : decltype(is_key_convertible_impl::check(nullptr)){}; - -#ifdef __INTEL_COMPILER -#undef decltype(...) -#endif - template struct toml_default_type{}; template<> struct toml_default_type{typedef Boolean type;}; template<> struct toml_default_type{typedef Integer type;}; @@ -137,6 +110,33 @@ template<> struct toml_default_type{typedef Table type;}; template<> struct toml_default_type{typedef void type;}; template<> struct toml_default_type{typedef void type;}; +template +struct is_exact_toml_type : disjunction< + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same + >{}; + +template +struct is_map : conjunction< + has_iterator, + has_value_type, + has_key_type, + has_mapped_type + >{}; + +template +struct is_container : conjunction< + negation>, + negation>, + has_iterator, + has_value_type + >{}; + struct storage_base { storage_base(): type(toml::value_t::Empty){} @@ -148,7 +148,8 @@ struct storage_base template struct storage : public storage_base { - static_assert(is_toml_array::value || is_toml_table::value, + static_assert(std::is_same::value || + std::is_same::value, "toml::detail::storage is for toml::Array or toml::Table!"); typedef T value_type;