Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::vector<> derivate with resize() that doesn't initialize primitives & forwarding construct_back
    primarykey
    data
    text
    <p>So there's a ton of cases where this it needed in performance sensitive applications, and I'm finally at the straw that broke the camels back. It needs to compile in C++98, as at least one of our platform only guarantees C++98 compliance.</p> <p>Edited hopefully to be a bit more clear with what I want.</p> <p>Example:</p> <pre><code>// This will allocate storage for 1024, and then loop 1024 times touching all of it just to place a 0 in it std::vector&lt; char &gt; buffer( 1024 ); // Now read will write into that buffer, overwriting the 0s ( we payed for the fill unnecessarily ) buffer.resize( read( someSource, &amp;buffer[0], buffer.size() ) ); </code></pre> <p>This is the common C interface, used with nearly all C libraries for writing data to a buffer. The same problems arise when dealing with buffers containing primitives in general. New resize would instead look something like this:</p> <pre><code>// Disabled for anything which doesn't pass boost::is_POD&lt; T &gt;, they get the standard version void resize( size_t a_NewSize ) { reserve( a_NewSize ); _end = _begin + a_NewSize; } </code></pre> <p>construct_back would be a forwarding constructor, for 1 const argument it would look something like this ( untested ):</p> <pre><code>template&lt; typename T1 &gt; void construct_back( const T1&amp; a_Arg1 ) { if( capacity() &lt;= size() ) // No room reserve( size() + 1 ); // Construct in place using Ts constructor that accepts const T1&amp; new (&amp;(*end()) T( T1 ); ++_end; // Account for new element } </code></pre> <p>construct_back would have to have all the possible number of arguments^2 overloads, this is the common brute force approach for perfect forwarding in C++98. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload