Skip to content

C++20 operators should be constexpr #313

@walbourn

Description

@walbourn

These manual comparison operators are not constexpr, so XMFLOAT3X3 comparisons cannot be used in constant expressions. It might be better to add constexpr to operator== and operator<=>.
Here is the suggested code:

    #if (__cplusplus >= 202002L)
        constexpr bool operator == (const XMFLOAT3X3& M) const noexcept
        {
            return _11 == M._11 && _12 == M._12 && _13 == M._13
                && _21 == M._21 && _22 == M._22 && _23 == M._23
                && _31 == M._31 && _32 == M._32 && _33 == M._33;
        }

        constexpr auto operator <=> (const XMFLOAT3X3& M) const noexcept
        {
            if (auto cmp = _11 <=> M._11; cmp != 0) return cmp;
            if (auto cmp = _12 <=> M._12; cmp != 0) return cmp;
            if (auto cmp = _13 <=> M._13; cmp != 0) return cmp;
            if (auto cmp = _21 <=> M._21; cmp != 0) return cmp;
            if (auto cmp = _22 <=> M._22; cmp != 0) return cmp;
            if (auto cmp = _23 <=> M._23; cmp != 0) return cmp;
            if (auto cmp = _31 <=> M._31; cmp != 0) return cmp;
            if (auto cmp = _32 <=> M._32; cmp != 0) return cmp;
            return _33 <=> M._33;
        }
    #endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    conformanceRelated to supporting non-MSVC compilers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions