tuple vector and initializer_list

前端 未结 3 541
太阳男子
太阳男子 2021-01-03 18:31

I tried to compile the following snippets with gcc4.7

vector > vp = {{1,\'a\'},{2,\'b\'}};
//For pair vector, it works like a char         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-03 19:15

    Annoying isn't it? I was also using pairs before - in a similar scenario and was surprised tuples do not support this, as the {} initialization syntax saves a lot of clutter. You can insert the elements manually in containers using make_tuple, so:

    vt.push_back(make_tuple(2,4.2,'b'));
    

    should work

提交回复
热议问题