This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
SFINAE question
- From: Onay Urfalioglu <onay dot urfalioglu at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 12 May 2010 23:51:57 +0300
- Subject: 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