I have a vector of boost::any and would like to find the index of a 'any' in this vector.
Something like this :
vector<any> values;
any valueISearch = ...;
find<A*>(valueISearch);
For this I try to compare 2 any values with the following method :
template <class T> bool IsValueEqualTo(any aniInVector, any value)
{
if (aniInVector.empty() && value.empty())
return true;
if (aniInVector.empty() && !value.empty())
return false;
if (!aniInVector.empty() && value.empty())
return false;
try
{
T left = boost::any_cast<T>(aniInVector);
T right = boost::any_cast<T>(value);
return left == right;
}
catch(const boost::bad_any_cast &exception)
{
}
return false;
}
The problem is that now when I do a anycast it only cast to the specific type and don't care about base types :
class A {};
class B: public A {};
B v1;
B v2;
IsValueEqualTo<A*>(&v1, &v2);