Hey! 
Recently a took a look at some public/private MMO bots, most of them written in C++.
Most of them shared a ugly problem: Their objectlist filtering was pretty dirty and non-reusable.
So I thought I might help someone if I show you how I do it in my bot, which I currently develope. 
The heart is a templated class 'Filter' (It doesn't need to be templated, but that's obviously the best way).
Code:
template<class Object>
class Filter
{ };
This class aims to store a set of filters and apply them to a list of objects.
But in which form are we going to store our filters?
That question should be answered with std::function, as it allows us to use almost everything as a filter (with boost:
ython you can even register Python functions as filters, cool eh?
)
So lets typedef a common type for filters, which shall take an object as argument and return true if the object is acceptable:
Code:
typedef std::function<bool (Object)> ObjectFilter;
Internally we use a std::vector to store those filters. The dynamic memory allocation is no problem, as it only should be once.
Code:
std::vector<ObjectFilter> m_filters;
Next, implement two constructors. A defaulted default-constructor and another constructor taking an initializer-list for more comfortable usage:
Code:
Filter() = default;
Filter(std::initializer_list<ObjectFilter> list)
: m_filters(list)
{ }
Not really necessary, but sometimes really helpfull (I started creating Filters dynamically from XML-Files):
Code:
void addFilter(ObjectFilter filter)
{
m_filters.push_back(filter);
}
Here comes the function which does all the magic:
Code:
template<typename InputIterator>
std::pair<InputIterator, InputIterator>
apply(InputIterator begin, InputIterator end) const
{
InputIterator removed = std::remove_if(begin, end, [&](Object cur)
{
for(ObjectFilter filter : this->m_filters)
if(!filter(cur))
return true;
});
return std::pair<InputIterator, InputIterator>(begin, removed);
}
We simply take a range as argument, apply the filters on it, move every unsuitable object to the end and return the range containing all left elements.
This is pretty performant as no copies/memory allocations are made but it alters the input range (which shouldn't be a problem).
Thats it !
Here's an example, similar to what I use to determine gatherable veins/herbs:
Code:
class DistanceLessThan
{
private:
float m_distance;
public:
DistanceLessThan(float distance)
: m_distance(distance)
{ }
bool operator(WoW::Object obj) const
{
auto playerPos = WoW::ObjectManager::get()->getActivePlayer().position();
return (playerPos.distanceTo(obj.position()) < m_distance);
}
};
void printGatherableObjects()
{
static Filter<WoW::Object> IsGatherable = { &WoW::canGather, DistanceLessThan(30.0) };
WoW::ObjectManager* mgr = WoW::ObjectManager::get();
auto filtered = IsGatherable.apply(mgr->first, mgr->last);
std::copy(filtered.first, filtered.second, std::ostream_iterator<WoW::Object>(std::cout));
}
And here's the complete Filter-class:
Code:
#include <vector>
#include <utility>
#include <functional>
#include <algorithm>
template<class Object>
class Filter
{
public:
typedef std::function<bool (Object)> ObjectFilter;
private:
std::vector<ObjectFilter> m_filters;
public:
Filter() = default;
Filter(std::initializer_list<ObjectFilter> list)
: m_filters(list)
{ }
void addFilter(ObjectFilter filter)
{
m_filters.push_back(filter);
}
template<typename InputIterator>
std::pair<InputIterator, InputIterator>
apply(InputIterator begin, InputIterator end) const
{
InputIterator removed = std::remove_if(begin, end, [&](Object cur)
{
for(ObjectFilter filter : this->m_filters)
if(!filter(cur))
return true;
});
return std::pair<InputIterator, InputIterator>(begin, removed);
}
};
Seems to be pretty obvious, but as many people fail at it, I thought it might help. 
Regards,
Flo