This IMHO is one of the drawbacks of the current C ++ standard. Vector makes a big replacement for C-arrays, but initializing one of them is much larger than PITA.
The best I've heard is the Boost destination package . According to the docs, you can do it with it:
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/assert.hpp>;
using namespace std;
using namespace boost::assign;
{
vector<int> values;
values += 1,2,3,4,5,6,7,8,9;
BOOST_ASSERT( values.size() == 9 );
BOOST_ASSERT( values[0] == 1 );
BOOST_ASSERT( values[8] == 9 );
}
source
share