Last active
February 28, 2019 17:50
-
-
Save adabo/91e6d59f5d72fccf2e8447113a741a88 to your computer and use it in GitHub Desktop.
trouble with remove_if
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
enum ItemName | |
{ | |
FOO, | |
BAR, | |
THING | |
}; | |
class Item | |
{ | |
public: | |
Item(ItemName itemName) | |
: mItemName(itemName){} | |
ItemName mItemName; | |
}; | |
class Game | |
{ | |
public: | |
Game(std::vector<Item> item); | |
void rmItem(ItemName itemName); | |
std::vector<Item> mItems; | |
}; | |
Game::Game(std::vector<Item> item) | |
: mItems(item) {} | |
void Game::rmItem(ItemName itemName) | |
{ | |
mItems.erase(std::remove_if( mItems.begin(), | |
mItems.end(), | |
[](auto &item) { return item.mItemName == itemName; }), | |
mItems.end()); | |
} | |
int main() | |
{ | |
Game game{ {FOO,BAR,FOO,THING,FOO} }; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment