Skip to content

Instantly share code, notes, and snippets.

@Astro36
Created March 29, 2020 14:18
Show Gist options
  • Save Astro36/f8a37e76f2bdad60409c4324d957ad35 to your computer and use it in GitHub Desktop.
Save Astro36/f8a37e76f2bdad60409c4324d957ad35 to your computer and use it in GitHub Desktop.
template<typename T, typename Index = std::size_t, typename = void>
struct has_subscript_operator : std::false_type {};
template<typename T, typename Index>
struct has_subscript_operator<T, Index, std::void_t<decltype(std::declval<T>()[std::declval<Index>()])>> : std::true_type {};
template<typename T, typename Index = int>
using has_subscript_operator_v = typename has_subscript_operator<T, Index>::value;
template<typename T>
using iterator_cat = typename std::iterator_traits<T>::iterator_category;
template<typename T, typename = void>
struct is_iterator : std::false_type {};
template<typename T>
struct is_iterator<T, std::void_t<iterator_cat<T>>> : std::true_type {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment