是否可以将用户定义的文字扩展为化合物?

时间:2016-02-17 13:16:32

标签: c++ operator-overloading user-defined-literals

是否可以扩展文字运算符以返回化合物?

示例:

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 个答案:

没有答案