I get two variables a and b and want to add them directly to a list of arrays. How can I avoid to define another array, which will be pushed into the list afterwards?
I am searching for a construction similar to the line beginning with //.
Minimal example:
#include <list>
#include <boost/array.hpp>
using namespace std;
int main()
{
cout << endl;
/* given values */
int a = 1;
int b = 2;
/* arrayList contains arrays of integers. */
list<boost::array<int, 2> > arrayList;
/* item to add values */
boost::array<int, 2> item;
item[0] = a;
item[1] = b;
arrayList.push_back(item);
// arrayList.push_back({{a, b}});
cout << arrayList.front()[0] << ", " << arrayList.front()[1] << endl;
return 0;
}
My g++ version is the following:
gcc-Version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5).
Compiling (within Eclipse) throws this warning listed as an error:
Warnung: erweiterte Initialisierungsliste nur mit -std=c++0x oder -std=gnu++0x verfügbar [standardmäßig aktiviert] main.cpp /testArrayListAndFind line 24 C/C++ Problem
which means: Extended initilization list only with ... or ... available.
You could use
boost::assign::list_ofif you don’t have C++11 support: