Like Tree1Likes

std:vector:resize in gcc4.2

This is a discussion on std:vector:resize in gcc4.2 within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia There is no need and it is a good thing to do so are two very ...

  1. #16
    bzt
    bzt is offline
    Registered User
    Join Date
    Feb 2012
    Posts
    10
    Quote Originally Posted by Elysia View Post
    There is no need and it is a good thing to do so are two very different things.
    You are kicking yourself and hurting everyone else by not updating.
    With latest GCC, you should be able to do

    Code:
    std::vector<int> test;
    std::for_each(test.begin(), test.end(), [&test](int size) { test.resize(size); });
    Now compare that to what you are trying to do.
    but do you know a 100% if i just can update gcc on an apple and use it with xcode ?

  2. #17
    bzt
    bzt is offline
    Registered User
    Join Date
    Feb 2012
    Posts
    10
    i would be extremely happy, because your code snippet looks so well ..

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    2,391
    building GCC from source is no trivial matter, but it's not terribly difficult. I recently built 4.7 from the git repository on a couple of systems, and after installing a few extra necessary packages, it built without incident, and works great. I highly recommend upgrading to at least 4.5, if not 4.6 or 4.7. pre-built packages may even be available for mac.

  4. #19
    bzt
    bzt is offline
    Registered User
    Join Date
    Feb 2012
    Posts
    10
    thanks elkvis, i will give that a shot if i am having more time .. for now i just edited stl_vector.h .. quite dirty .. but the executable now builds and runs fine ..

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    Or, you know, you could do it the way they did before C++11:
    Make a struct, add references to any members your lambda must be able to access, then initialize them in the constructor and overload operator () to act as a lambda.

    OR BETTER YET:
    Get rid of for_each and make a proper for loop. Seriously.
    This way you don't have to upgrade (but you should!), or write long cryptic lines or code OR hack header files (which you should NEVER do!).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. resize image
    By lamko in forum C Programming
    Replies: 22
    Last Post: 09-01-2011, 09:59 AM
  2. Resize Listview
    By mikeman118 in forum Windows Programming
    Replies: 4
    Last Post: 06-12-2008, 07:23 PM
  3. png Image Resize
    By bhupesh.kec in forum C Programming
    Replies: 3
    Last Post: 12-06-2007, 06:52 AM
  4. std::vector resize and Class copy constructor
    By pianorain in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2005, 12:52 PM
  5. .resize
    By psyko369 in forum C++ Programming
    Replies: 2
    Last Post: 02-14-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21