make_pair和大括号{}之间的区别,以便在C ++中分配一个对? [英] Difference between make_pair and curly brackets { } for assigning a pair in C++?

查看:92
本文介绍了make_pair和大括号{}之间的区别,以便在C ++中分配一个对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到回答这个问题的人,以下内容之间是否有区别:

I didn't find anyone answering this, is there any difference between the following :

v.push_back({x, y});

和:

v.push_back(make_pair(x, y));

假设v是这样声明的:

vector<pair<int,int> > v;

推荐答案

我在在线编译器中进行了尝试,据我所知,make_pair的优化程序集与{}语法相同.

I tried this in an online compiler, and as far as I can see the optimized assembly for make_pair is identical to {} syntax.

https://godbolt.org/z/P7Ugkt

这篇关于make_pair和大括号{}之间的区别,以便在C ++中分配一个对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆