0

Would it be possible to extend the literal operator to return compounds?

Example:

typedef struct { double a,b; } Pair;
Pair p = (Pair){1.2, 3.4}; // <-- Today: compound literal

/* Hypothetical future Operator: */
Pair operator"" _P(double a, double b) {
  return Pair(a,b);
}
...
Pair p = (1.2, 3.4)_P; // <-- Would it be possible?
ManuelAtWork
  • 2,198
  • 29
  • 34
  • You may still create a proposal. – Jarod42 Feb 17 '16 at 13:22
  • That would have zero chance to be accepted. All literals are currently tokens. You need an extremely good reason to change that. – n. m. could be an AI Feb 17 '16 at 13:46
  • This is like a postfix function call. I actually thought about this (I did literal ops for g++). I was thinking {1,2,3}_v for vector. Ultimately I decided that I'd rather read an honest ctor. As was said earlier, grammatically, this proposal is completely different. Plus aggregate init really gets you the terseness. Plus, putting an initlist in a function argument would be consumed by any container for example. – emsr Feb 18 '16 at 13:09

0 Answers0