[Bug c++/50711] [C++0x] substitution failure reports error with result_of

jarrydb at cse dot unsw.edu.au gcc-bugzilla@gcc.gnu.org
Thu Oct 13 03:32:00 GMT 2011


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



More information about the Gcc-bugs mailing list