mercredi 19 décembre 2012

The annoying push_back.....

Maybe you know, but maybe not,
but one of the really nice feature coming in the C++11 standard is the "initializer list".

In fact with C++11, you can now write:
std:vector vec = {"blog", "msg"};

see http://en.wikipedia.org/wiki/C%2B%2B11#Core_language_usability_enhancements

But if you are still using the old C++, you can at least try to avoid the push_back usage...

Instead of writing

std:vector vec;
vec.push_back("blog");
vec.push_back("msg");

let's use Boost/Assign to offer a += operator supporting variable number of arguments

#include "boost/assign.hpp"
std:vector vec;
vec += "blog", "msg";