From 09c169c2d983714ec875fa3013123a4566b15ecd Mon Sep 17 00:00:00 2001 From: fpeng1985 Date: Thu, 19 Sep 2019 02:24:24 +0800 Subject: [PATCH] refine the implementation of has_find type_traits (#319) * refine the implementation of has_find type_traits * Format fix --- include/CLI/Validators.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/CLI/Validators.hpp b/include/CLI/Validators.hpp index e3736845..b4586ed1 100644 --- a/include/CLI/Validators.hpp +++ b/include/CLI/Validators.hpp @@ -501,14 +501,14 @@ template std::string generate_map(const T &map, bool key_only = fal return out; } -template struct sfinae_true : std::true_type {}; -/// Function to check for the existence of a member find function which presumably is more efficient than looping over -/// everything -template -static auto test_find(int) -> sfinae_true().find(std::declval()))>; -template static auto test_find(long) -> std::false_type; +template struct has_find { + template + static auto test(int) -> decltype(std::declval().find(std::declval()), std::true_type()); + template static auto test(...) -> decltype(std::false_type()); -template struct has_find : decltype(test_find(0)) {}; + static const auto value = decltype(test(0))::value; + using type = std::integral_constant; +}; /// A search function template ::value, detail::enabler> = detail::dummy>