This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: STL last arg to vector::resize


On 18/08/07, John L. Kulp <jlkjr@bioleap.com> wrote:
> Can anyone give me the rationale about why vector::resize passes its last argument by value?  On the surface it seems wrong to incur the cost of copying for no reason I can see. Also, MSVC and gcc disagree about whether the arg should be const.  Again, is there any reason it shouldn't be?  Perhaps this has been discussed, in which case could someone point me to that?  Thanks.  Note that passing by value means that aligned vectors as required for SSE code will fail to compile due to this.

See http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#679
for a summary of why it works like that today. I don't know if Howard
would recommend GCC should change the signature before that issue is
resolved one way or another.

But to address your problem today, can you use insert or push_back
instead of resize if pass-by-value doesn't work for aligned types?

MSVC and GCC don't really disagree, see 8.5.3 paragraph 3 of the C++
standard; cv-qualifiers on parameters do not affect the function type.
 e.g.
    void f(int);   // declare
    void f(const int) { } // define
this declaration and definition refer to the same function. To quote
the standard "Such cv-qualifiers affect only the definition of the
parameter within the body of the function; they do not affect the
function type."
So, is there any particular argument that it _should_ be const?

Jon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]