What is an ISO C ++ way to directly define a conversion function for an array reference?

According to the standard, the conversion function has an id-identifier for the id function operator, which will look like, say operator char(&)[4], I think. But I can’t figure out where to place the list of function parameters. gcc does not accept any of operator char(&())[4]or operator char(&)[4]()or anything that I can think of.

Now gcc seems to accept (&operator char ())[4], but clang does not, and I am not inclined to this either, since it does not seem to correspond to the grammar, as I understand it.

I do not want to use typedefit because I want to avoid using its namespace.

+5
source share
2

template<typename T>
struct identity { typedef T type; };

struct sample {
  operator identity<char[4]>::type &() {
    ...
  }
};

, . . , ++ 0x , .

struct sample {
  template<typename T>
  using id = T;

  template<typename T, int N>
  operator id<T[N]> &() {
    ...
  }
};

identity typedef, T N, .

+9

++ . , typedef-name .

, typedef

struct S {
  int a[4];

  typedef int A[4];
  operator A&() { return a; }
};
+4

All Articles