insert vs emplace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

I have been pondering the attached program for a while and can't figure
out if it invokes undefined behaviour or what the proper output of it
should be so I am hoping someone here could help me finding the relevant
parts of the c++ standard.

/MF
#include <iostream>
#include <vector>
int main()
{
	{
		std::vector<int> v { 1, 2, 3 };
		v.reserve(4);
		v.insert(v.begin(), v[2]);
		std::cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' << v[3] << '\n';
	}
	{
		std::vector<int> v { 1, 2, 3 };
		v.reserve(4);
		v.emplace(v.begin(), v[2]);
		std::cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' << v[3] << '\n';
	}
}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux