Solved Erase Remove Idiom Predicate

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,164
78,998
2,399
I am currently using the Erase Remove Idiom to remove elements from my Vector of pointers if they are NULL using this:
C++:
BestTarget.erase(std::remove(begin(BestTarget), end(BestTarget), nullptr), end(BestTarget));
BestTarget is a vector of pointers to structs
C++:
vector<OtherPlayers_struct*> BestTarget;

I want to use a predicate that will Erase/Remove elements if BestTarget->bNotVisible = true

My call would be:
C++:
BestTarget.erase(std::remove(begin(BestTarget), end(BestTarget), NotVisibleEraser), end(BestTarget));
The predicate would be something like this but I know I'm not doing it right.
C++:
bool NotVisibleEraser(OtherPlayers_struct * temp){
	return temp->bNotVisible = true;
}
How would I write the predicate?
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,164
78,998
2,399
I ended up writing this very long sort comparison to sort the vector rather than delete invalid targets, this way when I make a radar I can use the same player array as the aimbot duh!
C++:
bool comparison(playerClass &lhs, playerClass &rhs){
	//if not alive, move to end
	if (lhs.State != 0)
		return false;


	else
	{
		if (GameData.bTeamGame)
		{
			//if same team, move to end
			if (lhs.Team == localPlayer.Team)
			{
				return false;
			}


			switch (SortMethod)
			{
			case Angle:
			{
				return lhs.fCrosshairToTargetAngle < rhs.fCrosshairToTargetAngle;
			}
			case Distance:
			{
				float templhs = lhs.fCrosshairToTargetAngle + (lhs.Distance * 1.3);
				float temprhs = rhs.fCrosshairToTargetAngle + (rhs.Distance * 1.3);
				return templhs < temprhs;
			}
			}
		}


		else //for death match games
		{


			switch (SortMethod)
			{
			case Angle:
			{
				return lhs.fCrosshairToTargetAngle < rhs.fCrosshairToTargetAngle;
			}
			case Distance:
			{
				float templhs = lhs.fCrosshairToTargetAngle + (lhs.Distance * 1.3);
				float temprhs = rhs.fCrosshairToTargetAngle + (rhs.Distance * 1.3);
				return templhs < temprhs;
			}
			}


		}
	}


}
 

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51
I am currently using the Erase Remove Idiom to remove elements from my Vector of pointers if they are NULL using this:
C++:
BestTarget.erase(std::remove(begin(BestTarget), end(BestTarget), nullptr), end(BestTarget));
BestTarget is a vector of pointers to structs
C++:
vector<OtherPlayers_struct*> BestTarget;

I want to use a predicate that will Erase/Remove elements if BestTarget->bNotVisible = true

My call would be:
C++:
BestTarget.erase(std::remove(begin(BestTarget), end(BestTarget), NotVisibleEraser), end(BestTarget));
The predicate would be something like this but I know I'm not doing it right.
C++:
bool NotVisibleEraser(OtherPlayers_struct * temp){
	return temp->bNotVisible = true;
}
How would I write the predicate?
afaik, if i'm not wrong this would make temp->bNotVisible = true and then just returns true always.

If you want to return the property just use temp->bNotVisible
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,164
78,998
2,399
Thanks till0sch I'll give that a test later
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods