Topic: -1?Q?Request f r std::vector and possibly others: minima


Author: henrikv <henrik.vallgren@stream-space.com>
Date: Mon, 19 Mar 2012 23:35:35 -0700 (PDT)
Raw View
Hello group!

When writing parallel code, I often allocate a vector for results. I
allocate the complete vector with a single resize. What I'd like to do
is to tell the resize not to initialize the content, since this will
be overwritten anyway. I'd figure something like:

struct no_init {} g_no_int;

struct Dummy
{
 Dummy(int a_=0) : a(a_) {}
 Dummy(const no_init &) {} // Without a v-table, this shouldn't need
to
touch any part of the created object?

 int a;
};

void foo()
{
 std::vector<Dummy> dummies;
 dummies.resize(1000, g_no_int);
 // ...
}

Proposal: add a method to std::vector that allows resize with a
different constructor than default or copy
constructor:

               template <typename T2>
               void resize_construct_using_translation(size_t n, const T2 &t2);

Any thoughts on this?

Best regards,
Henrik Vallgren


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]