This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/50711] [C++0x] substitution failure reports error with result_of
- From: "jarrydb at cse dot unsw.edu.au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 13 Oct 2011 03:32:05 +0000
- Subject: [Bug c++/50711] [C++0x] substitution failure reports error with result_of
- Auto-submitted: auto-generated
- References: <bug-50711-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50711
--- Comment #3 from Jarryd Beck <jarrydb at cse dot unsw.edu.au> 2011-10-13 03:32:05 UTC ---
The following code works:
struct Tuple
{
int a, b, c;
};
struct array_get
{
template <typename T>
const T&
operator()(const T& t)
{
return t;
}
template <typename Array, typename First, typename... Location>
auto
operator()(const Array& a, First f, Location... loc)
// -> typename std::result_of<array_get(decltype(a[f]), Location...)>::type
-> decltype(operator()(a[f], loc...))
{
return operator()(a[f], loc...);
}
};
struct Array
{
int array[5][5][5];
Array()
{
for (int i = 0; i != 5*5*5; ++i)
{
reinterpret_cast<int*>(array)[i] = i;
}
}
int get(const Tuple& t)
{
return array[t.a][t.b][t.c];
}
template <typename... Location>
//typename std::result_of<array_get(int[5][5][5], Location...)>::type
auto
get(Location... loc)
-> decltype(array_get()(array, loc...))
{
return array_get()(array, loc...);
}
};
int main(int argc, char *argv[])
{
Array a;
Tuple t{3,4,1};
//return a.get(1,2,3);
return a.get(t);
}