Re: vector assign
On May 24, 1:48 am, acehr...@gmail.com wrote:
On May 23, 3:40 pm, stephen b <ker...@audiospillage.com> wrote:
Hi all, personally I'd love to be able to do something like this:
vector<int> v;
v.assign(1, 2, 5, 9, 8, 7) etc
Checkout Boost's Assign Library. You can do these:
vector<int> v;
v += 1,2,3,4,5,6,7,8,9;
Institutionalized obfuscation, anyone? That statement has a
predefined meaning in C++, without any library, and any code
which changes a predefined meaning should be avoided at all
costs.
or
vector<int> v = list_of(1)(2)(3);
That's better. A lot of the time, of course, simply:
static int const init[] = { 1, 2, 5, 9, 8, 7 } ;
std::vector< int > v( begin( init ), end( init ) ) ;
is just as good.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34