Last active
February 25, 2016 12:52
-
-
Save oliora/216dd6f2f276a8a27cb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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