Skip to content

Instantly share code, notes, and snippets.

@oliora
Last active February 25, 2016 12:52
Show Gist options
  • Save oliora/216dd6f2f276a8a27cb0 to your computer and use it in GitHub Desktop.
Save oliora/216dd6f2f276a8a27cb0 to your computer and use it in GitHub Desktop.
// Developing of the topic, see previous gists:
// 1. https://gist.github.com/oliora/b8207b4a74a6bb868ef4
// 2. https://gist.github.com/pudov/0b1572989c418684c381
#include <type_traits>
#include <utility>
#include <vector>
#include <set>
// Let's use std::void_t. Unfortunately it's introduced in C++17 but you can easily add it by yourself
// See more at http://en.cppreference.com/w/cpp/types/void_t
namespace std {
template<typename... Ts> struct make_void { typedef void type;};
template<typename... Ts> using void_t = typename make_void<Ts...>::type;
}
template< class, class = std::void_t<> >
struct has_own_find : std::false_type {};
template< class T >
struct has_own_find<T, std::void_t<decltype(std::declval<T>().find(std::declval<typename T::key_type>()))>> : std::true_type {};
int main()
{
static_assert(!has_own_find<std::vector<int>>::value, "vector has NO find");
static_assert( has_own_find<std::set<int>>::value, "set has find");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment