1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-30 12:43:52 +00:00

refine the implementation of has_find type_traits (#319)

* refine the implementation of has_find type_traits

* Format fix
This commit is contained in:
fpeng1985 2019-09-19 02:24:24 +08:00 committed by Henry Schreiner
parent b029b325b5
commit 09c169c2d9

View File

@ -501,14 +501,14 @@ template <typename T> std::string generate_map(const T &map, bool key_only = fal
return out; return out;
} }
template <typename> struct sfinae_true : std::true_type {}; template <typename C, typename V> struct has_find {
/// Function to check for the existence of a member find function which presumably is more efficient than looping over template <typename CC, typename VV>
/// everything static auto test(int) -> decltype(std::declval<CC>().find(std::declval<VV>()), std::true_type());
template <typename T, typename V> template <typename, typename> static auto test(...) -> decltype(std::false_type());
static auto test_find(int) -> sfinae_true<decltype(std::declval<T>().find(std::declval<V>()))>;
template <typename, typename V> static auto test_find(long) -> std::false_type;
template <typename T, typename V> struct has_find : decltype(test_find<T, V>(0)) {}; static const auto value = decltype(test<C, V>(0))::value;
using type = std::integral_constant<bool, value>;
};
/// A search function /// A search function
template <typename T, typename V, enable_if_t<!has_find<T, V>::value, detail::enabler> = detail::dummy> template <typename T, typename V, enable_if_t<!has_find<T, V>::value, detail::enabler> = detail::dummy>