How to check for the existence of a subscript operator?
问题 I want to write a type trait which uses SFINAE to check a type for the existence of a subscript expression. My initial attempt below seems to work when the subscript expression is possible but does not work when the bracket operator does not exist. #include <iostream> #include <vector> #include <cassert> template<class T, class Index> struct has_subscript_operator_impl { template<class T1, class Reference = decltype( (*std::declval<T*>())[std::declval<Index>()] ), class = typename std::enable