initializer_list
の順序付けられていない要素をどのように初期化できますか?std :: initializer_listの初期化
#include <unordered_map>
#include <string>
using Type = std::unordered_map<std::string, int>;
void foo(std::initializer_list<Type> l) {}
int main()
{
Type x = {{"xxx", 0}, {"yyy", 1}}; // compile fine
// std::initializer_list<Type> y = {{"xxx", 0}, {"yyy", 1}};
// foo({{"xxx", 0}, {"yyy", 1}});
}
私は最初の行のコメントを解除した場合、私は(G ++ 6.1.1)エラーました:私がしたいものを、終わりに
error: could not convert ‘{{"xxx", 0}, {"yyy", 1}}’ from ‘’ to ‘std::initializer_list, int> >’ std::initializer_list y = {{"xxx", 0}, {"yyy", 1}};
をたとえば、次のコードを考えてみ
コンパイルもしない2番目のコメント行のようにfoo
を呼び出すことができます。
'foo({{{" xxx "、0}、{" yyy "、1}}}))' – jaggedSpire