C++ STL algorithm - erase-remove idiom -- std::remove(_if, _copy_if) | Modern Cpp Series Ep. 154

  Рет қаралды 1,266

Mike Shah

Mike Shah

Күн бұрын

►Full C++ Series Playlist: • The C++ Programming La...
►Find full courses on: courses.mshah.io/
►Join as Member to Support the channel: / @mikeshah
►Lesson Description: In this lesson I show you how to remove elements from a container! This is the popular erase-remove idiom that will actually remove elements from a data structure (a common search on stack overflow!). Note that we'll look at 'erase_if' in a later video as well.
►KZbin Channel: / mikeshah
►Please like and subscribe to help the channel!
►Join our free community: courses.mshah....

Пікірлер: 8
@yusuke1435
@yusuke1435 11 ай бұрын
Great video
@MikeShah
@MikeShah 11 ай бұрын
Cheers!
@j1952d
@j1952d 11 ай бұрын
The remove_if() eliminated the 2 and the 4 !
@MikeShah
@MikeShah 11 ай бұрын
Timestamp? I'll add in the description notes if there are corrections :)
@j1952d
@j1952d 11 ай бұрын
@@MikeShah Around 23 minutes. The 1,2,4,3,8,5,7,6 was reduced to 1,3,8,5,7 at one stage IIRC - I'm out'n'about at present, but I'll check it out later if you want. I'm sure something fishy went on there!
@MikeShah
@MikeShah 11 ай бұрын
​@@j1952d Looks like remove_if is doing the right thing, but printing it right after is probably a bit misleading (since we should really call erase to remove the elements) probably immediately after the remove_if call. So I think we're just printing one past the end which is probably a bug itself (again, need to erase first) :)
@j1952d
@j1952d 11 ай бұрын
@@MikeShah Makes me wonder if some of the algorithms are more trouble than they're worth! Take half a day to learn what you could do in half an hour with a couple of for() loops! Maybe good for very big projects with lots of developers, all having a go at messing it up!. I guess I've been a loner too long.
@MikeShah
@MikeShah 11 ай бұрын
@@j1952d Most algorithms I think well worth it. Luckily in C++ 20 we finally get erase :) (coming up in the series) en.cppreference.com/w/cpp/container/vector/erase2
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 57 МЛН
C++ Should Be C++ - David Sankel - C++Now 2024
1:28:49
CppNow
Рет қаралды 18 М.
STL std::set | Modern Cpp Series Ep. 121
24:15
Mike Shah
Рет қаралды 3,6 М.
std::move and the Move Assignment Operator in C++
16:06
The Cherno
Рет қаралды 171 М.
No, Einstein Didn’t Solve the Biggest Problem in Physics
8:04
Sabine Hossenfelder
Рет қаралды 300 М.
C++ Weekly - Ep 332 - C++ Lambda vs std::function vs Function Pointer
16:30
C++ Weekly With Jason Turner
Рет қаралды 33 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,2 МЛН
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 57 МЛН