Пример #1
0
bool variant_compare_less(const variant& lhs, const type& lhs_type, const variant& rhs, const type& rhs_type)
{
    if (lhs_type.is_arithmetic() && rhs_type.is_arithmetic())
    {
        if (is_floating_point(lhs_type) || is_floating_point(rhs_type))
            return (lhs.to_double() < rhs.to_double());
        else
            return (lhs.to_int64() < rhs.to_int64());
    }
    else
    {
        variant lhs_tmp;
        if (lhs.convert(rhs_type, lhs_tmp))
            return lhs_tmp.compare_less(rhs);

        if (!lhs.is_nullptr() && rhs.is_nullptr())
            return false;

        // as last try, do a string conversion
        bool ok1 = false;
        bool ok2 = false;
        auto ret = (lhs.to_string(&ok1) < rhs.to_string(&ok2));
        if (ok1 && ok2)
            return ret;
        else
            return (lhs_type < rhs_type);
    }
}