This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

SFINAE question 2


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>();
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]