I'm having trouble doing some overloads.
It's trying to run this on every instance of the << or >> operators... I ONLY want it to do that if they contain the type any, explicitly... I don't want it to run the constructor!
Be prepared for a lot of code:
Code:
template <any, typename UnknownType>
any operator <<(const any & lhs, const UnknownType & rhs)
{
any result;
if (lhs.type() == typeid(UnknownType)) // check that types are same.
// don't use float or double!
result = any_cast<UnknownType>(lhs) << rhs;
return result; // returns a copy of result
}
Code:
template <typename UnknownType>
UnknownType operator <<(const UnknownType & lhs, const any & rhs)
{
UnknownType result;
if (rhs.type() == typeid(UnknownType)) // check that types are same.
// don't use float or double!
result = lhs << any_cast<UnknownType>(rhs);
return result; // returns a copy of result
}
Code:
template <any, typename UnknownType>
any operator >>(const any & lhs, const UnknownType & rhs)
{
any result;
if (lhs.type() == typeid(UnknownType)) // check that types are same.
// don't use float or double!
result = any_cast<UnknownType>(lhs) >> rhs;
return result; // returns a copy of result
}
Code:
template <typename UnknownType>
UnknownType operator >>(const UnknownType & lhs, const any & rhs)
{
UnknownType result;
if (rhs.type() == typeid(UnknownType)) // check that types are same.
// don't use float or double!
result = lhs >> any_cast<UnknownType>(rhs);
return result; // returns a copy of result
}
Its having trouble figuring out which overloads to do.
I believe this is because it tries to do the one with UnknownType as parameter 1 instead of the ostream/istream...
What am I doing wrong?