是否可以使用初始化列表创建临时 structs/classes?

Is it possible to create temp structs/classes with initializer lists?

这看起来是一个非常基本的问题,应该有一个明确的谷歌搜索答案,但到目前为止我没能找到它。 似乎答案是否定的,但我想确定一下。 我的意思是这样的:

struct A { int a,b; };
void foo(const A&); // just some function
foo(A{1,2}); // doesn't work, but it was a long shot
foo(A({1,2})); // looks like it could have worked, but it doesn't
foo(A(std::initializer_list<int>({1,2}))); // ugly and doesn't work either anyway

更新: 选项 2 实际上有效(以及更简单的 foo({1,2})),但仅在 vs2013 中有效,在 2012 中无效。

更新#2:来吧,有必要这么努力地否决它吗?知道它只适用于从 vs2013 开始仍然很有用。

甚至比这更容易。看看统一初始化的威力:

foo({1,2});