Would it be possible to extend user-defined literals to compounds?

71 Views Asked by At

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?
0

There are 0 best solutions below