From 1c5c0e857230602ca86d4912dd15c5578aa7ffba Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Apr 2017 13:37:39 +0900 Subject: [PATCH] add some meta functions --- toml.hpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/toml.hpp b/toml.hpp index d32f25a..dae95cd 100644 --- a/toml.hpp +++ b/toml.hpp @@ -676,5 +676,89 @@ value::cast() std::string(" is not query type: ") + stringize(T)); return switch_cast::invoke(*this); } + +/* -------------------------------------------------------------------------- */ + +namespace detail +{ + +struct has_iterator_impl +{ + template static std::true_type check(typename T::iterator*); + template static std::false_type check(...); +}; +struct has_value_type_impl +{ + template static std::true_type check(typename T::value_type*); + template static std::false_type check(...); +}; +struct has_key_type_impl +{ + template static std::true_type check(typename T::key_type*); + template static std::false_type check(...); +}; +struct has_mapped_type_impl +{ + template static std::true_type check(typename T::mapped_type*); + template static std::false_type check(...); +}; + +template +struct has_iterator : decltype(has_iterator_impl::check(nullptr)){}; +template +struct has_value_type : decltype(has_value_type_impl::check(nullptr)){}; +template +struct has_key_type : decltype(has_key_type_impl::check(nullptr)){}; +template +struct has_mapped_type : decltype(has_mapped_type_impl::check(nullptr)){}; + +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>{}; + +struct is_key_convertible_impl +{ + template + static std::is_convertible + check(typename T::key_type*); + + template static std::false_type check(...); +}; +template +struct is_key_convertible : decltype(is_key_convertible_impl::check(nullptr)){}; + +} // detail + +template +struct is_castable : std::false_type{}; +template +struct is_castable : std::integral_constant::value>{}; +template +struct is_castable : std::integral_constant::value>{}; +template +struct is_castable : std::integral_constant::value>{}; +template +struct is_castable : std::integral_constant::value>{}; +template +struct is_castable : std::integral_constant::value>{}; +template +struct is_castable : std::integral_constant::value || toml::detail::is_container::value>{}; +template +struct is_castable : std::integral_constant::value && toml::detail::is_key_convertible::value>{}; +template +struct is_castable : std::true_type{};// XXX + }// toml #endif// TOML_FOR_MODERN_CPP