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


Hi, 

the following code, which tries to specialize on template function overloading  
fails to compile:
--------------------------------------------------------------------------------------------------------
#include <iostream>
#include <vector>

template< typename T_VECTOR >
void f(const T_VECTOR &a, decltype(a[0]) t = 0) {
    std::cout << "has operator[] \n";
}
template< typename T >
void f(const T &a, decltype(a+1) t = 0) {
    std::cout << "has operator+(int)\n";
}


int main() {
    std::vector< int > a;
    int c;
    f(a);
    f(c);
}
-----------------------------------------------------------------------------------------------------
compiled with
g++-4.5 -std=c++0x code.cpp

it gives:

code.cpp: In function âint main()â:
code.cpp:19:8: error: subscripted value is neither array nor pointer


To my understanding, it should compile fine, since f(c) should resolve to the 
second overload of f(). Is this a bug in g++-4.5?

Thanks for any hints,

Onay Urfalioglu


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