From fcd6e47500a377dabda1c8949d7f7557c68e8c45 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 27 Mar 2020 18:01:47 +0900 Subject: [PATCH] feat: add meta funcs, has_reserve/push_back_method --- toml/traits.hpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/toml/traits.hpp b/toml/traits.hpp index 4fc1bda..2fd36a2 100644 --- a/toml/traits.hpp +++ b/toml/traits.hpp @@ -43,17 +43,23 @@ struct has_mapped_type_impl template static std::true_type check(typename T::mapped_type*); template static std::false_type check(...); }; -struct has_resize_method_impl +struct has_reserve_method_impl { - constexpr static std::size_t dummy=0; - template static std::true_type check(decltype(std::declval().resize(dummy))*); template static std::false_type check(...); + template static std::true_type check( + decltype(std::declval().reserve(std::declval()))*); +}; +struct has_push_back_method_impl +{ + template static std::false_type check(...); + template static std::true_type check( + decltype(std::declval().push_back(std::declval()))*); }; - struct is_comparable_impl { - template static std::true_type check(decltype(std::declval() < std::declval())*); template static std::false_type check(...); + template static std::true_type check( + decltype(std::declval() < std::declval())*); }; struct has_from_toml_method_impl @@ -91,7 +97,9 @@ 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 has_resize_method : decltype(has_resize_method_impl::check(nullptr)){}; +struct has_reserve_method : decltype(has_reserve_method_impl::check(nullptr)){}; +template +struct has_push_back_method : decltype(has_push_back_method_impl::check(nullptr)){}; template struct is_comparable : decltype(is_comparable_impl::check(nullptr)){};