What is the easiest way to initialize a std::vector with hardcoded elements?

I can create an array and initialize it like this: int a[] = {10, 20, 30}; How do I create a std::vector and initialize it similarly elegant? The best way I know is: std::vector<int> ints; ints.push_back(10); ints.push_back(20); ints.push_back(30); Is there a better way? 29 s 29 If your compiler supports C++11, you can simply do: … Read more

push_back vs emplace_back

I’m a bit confused regarding the difference between push_back and emplace_back. void emplace_back(Type&& _Val); void push_back(const Type& _Val); void push_back(Type&& _Val); As there is a push_back overload taking a rvalue reference I don’t quite see what the purpose of emplace_back becomes? 7 s 7 In addition to what visitor said : The function void emplace_back(Type&& … Read more