Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concat std::vector and initializer list

Tags:

c++

c++11

In c++11 you can do this wonderful syntax:

vector<int> numbers = {1, 2, 3}; 

Is there a way to concatenate a further initializer list onto an existing vector?

numbers.??? ({4, 5, 6}); 

or

std::??? (numbers, {4, 5, 6}); 
like image 539
Eric B Avatar asked Oct 30 '13 17:10

Eric B


1 Answers

You can use std::vector::insert for that:

#include <vector>  vector<int> numbers = {1, 2, 3}; numbers.insert( numbers.end(), {4, 5, 6} ); 
like image 119
Pierre Fourgeaud Avatar answered Sep 28 '22 10:09

Pierre Fourgeaud