I want to overload pretty much every operator possible... however, I have to have two overloads, like this:

PHP Code:
    template <typename UnknownType>
    
any operator +(const any lhs, const UnknownType rhs)
    {
        
any result;

        if (
lhs.type() == typeid(UnknownType))    // check that types are same.
                                                // no support for compatible but not same,
                                                // sorry. Too much work to check for
                                                // int and float, etc.
            
result any_cast<UnknownType>(lhs) + rhs;

        return 
result;   // returns a copy of result
    
}

    
template <typename UnknownType>
    
UnknownType operator +(const UnknownType lhs, const any rhs)
    {
        
UnknownType result;

        if (
rhs.type() == typeid(UnknownType))    // check that types are same.
                                                // no support for compatible but not same,
                                                // sorry. Too much work to check for
                                                // int and float, etc.
            
result lhs any_cast<UnknownType>(rhs);

        return 
result;   // returns a copy of result
    

Since I plan on overloading close to 50... is there a way I can make the amount of code way less?

The body of each type would be identical, just the name of the overload (that includes type) would be different.

So if the overloads where the any comes first and the ones where it comes second... is there any way to do this without having 100 overloads at 8 lines of code?