I've written some template-meta nonsense to detect if class methods exists.
The template struct has_subscript is specialized so that the second template parameter is void if the first template parameter has a subscript operator. If the subscript operator is found, the specialization is used, otherwise SFINAE defaults to the non-specialized version.
I have the code working for a simple struct foo (it's templated just to better match std::vector), but it unexpectedly fails with std::vector.
demo link https://godbolt.org/z/5-QzAp
#include <type_traits>
#include <iostream>
#include <vector>
using namespace std;
template <typename>
struct void_wrap
{ using type = void; };
template <typename T, typename = void>
struct has_subscript
{
static constexpr bool value = false;
};
template <typename T>
struct has_subscript <T, typename void_wrap<typename result_of<decltype(&T::operator[])(T,int)>::type>::type >
{
static constexpr bool value = true;
};
template <typename T>
struct foo
{
double operator[](size_t x){return 0.0;}
};
int main()
{
cout << has_subscript<foo<int>>::value;
cout << has_subscript<vector<int>>::value;
}