The following code compiles fine with g++-4.7.1 in c++11 mode, but I
think it should give errors for the last source line "auto res2 = 2 *
std::list<int>();" (SFINAE ?)
// compile cmd:
// g++ c++11-test.cpp -o cpp11-test -std=c++11
#include <vector>
#include <list>
template<typename T>
struct HasRandomAccessOp {
HasRandomAccessOp(const T &v) {
typedef decltype(v[0]) test_type;
}
};
template<typename T, typename T_VECTOR>
int operator*(const T &l, const T_VECTOR &r) {
typedef decltype(HasRandomAccessOp<T_VECTOR>(r))
random_access_test_type;
return 1;
}
int main() {
std::vector<int> iv = {1,2};
auto res1 = 1 * iv;
auto res2 = 2 * std::list<int>();
}