Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: won't compile?

58 views
Skip to first unread message

Ian Collins

unread,
Apr 3, 2015, 2:22:04 AM4/3/15
to
SpreadTooThin wrote:
> void searchout(void) {
>
> string l, t;
> for (std::vector<string>::iterator it = logLines.begin() ; it != logLines.end(); ++it) {
> for (std::vector<string>::iterator thrd = threadIds.begin() ; thrd != threadIds.end(); ++thrd) {
> l = *it;
> t = *thrd;
> if (l.substr(t) != string::npos) { // Something is wrong here?
>
> }
> }
> }
> }
>
> what is wrong with this if statement? l.substr(t) compiler doesn't like it.

Your code would be a lot cleaner with modern C++:

for( auto longLine : logLines )
{
for( auto threadId : threadIds )
{
// stuff
}
}

--
Ian Collins

SpreadTooThin

unread,
Apr 5, 2015, 2:44:06 PM4/5/15
to
Thanks. I did not know that! :)

Juha Nieminen

unread,
Apr 7, 2015, 4:36:26 AM4/7/15
to
Ian Collins <ian-...@hotmail.com> wrote:
> for( auto longLine : logLines )
> {
> for( auto threadId : threadIds )
> {
> // stuff
> }
> }

Wouldn't it be better to use "auto&" (or "const auto&" if you don't need
to modify the elements)? Else you'll be getting copies of the elements
(which might be expensive).

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Jorgen Grahn

unread,
Apr 7, 2015, 9:04:56 AM4/7/15
to
On Tue, 2015-04-07, Juha Nieminen wrote:
> Ian Collins <ian-...@hotmail.com> wrote:
>> for( auto longLine : logLines )
>> {
>> for( auto threadId : threadIds )
>> {
>> // stuff
>> }
>> }
>
> Wouldn't it be better to use "auto&" (or "const auto&" if you don't need
> to modify the elements)? Else you'll be getting copies of the elements
> (which might be expensive).

I was going to complain about that, but he was only emulating what was
already there. Perhaps "// stuff" needs to mutate longLine or threadId?
Although it seems very unlikely.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
0 new messages