POV-Ray : Newsgroups : povray.off-topic : Standard libraries : Re: Standard libraries Server Time
6 Sep 2024 17:20:36 EDT (-0400)
  Re: Standard libraries  
From: Nicolas Alvarez
Date: 7 Mar 2009 17:39:52
Message: <49b2f7b8@news.povray.org>
Darren New wrote:
> Warp wrote:
>>     std::for_each(someList, [&total](int x) { total += x });
> 
> And, really, what's the advantage of this over a normal for loop?

You tell me.

int total = 0;
std::vector<int> someList;

std::for_each(someList, [&total](int x) {
   total += x;
});

vs

int total = 0;
std::vector<int> someList;

for (std::vector<int>::const_iterator i = someList.begin(); i !=
someList.end(); ++i) {
    total += *i;
}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.