BigUglySpider / EmuLibs

Selection of libraries designed to be used with Emu projects. This was originally a Math library only, but has since been changed to hold all Emu libraries to enable consistency in changes to dependencies (such as EmuCore modifications).
https://biguglyspider.github.io/math
0 stars 0 forks source link

[EmuMath] Replace recursive Vector Cmp with fold expressions #47

Open BigUglySpider opened 2 years ago

BigUglySpider commented 2 years ago

Fold expressions would be preferable as it would 1: clean up code, and 2: provide a much cleaner piece for the compiler to read and optimise, and likely reduce compile times (marginally) due to the removal of recursive template instantiations.

This could also produce some better short-circuit optimisations, although I am not too keenly aware of how these optimisations are delivered.

Nonetheless, return (... && cmp_(_vector_get_theoretical<Indices_>(lhs_), _vector_get_theoretical<Indices_>(rhs_)));, and return (... || cmp_(_vector_get_theoretical<Indices_>(lhs_), _vector_get_theoretical<Indices_>(rhs_))); are significantly easier to parse and maintain compared to the current:

return joiner_
(
    cmp_(_vector_get_theoretical<Index_>(lhs_), _vector_get_theoretical<Index_>(std::forward<RhsVector_>(rhs_))),
    _vector_cmp_rhs_vector<NoCmpReturn_, Index_ + 1, EndIndex_, Cmp_, Joiner_, LhsSize_, LhsT_, RhsVector_>
    (
        cmp_,
        joiner_,
        lhs_,
        std::forward<RhsVector_>(rhs_)
    )
);
BigUglySpider commented 2 years ago

This issue was raised when drafting plans for Matrix comparisons and deciding that this recursive approach would be far too difficult to parse for maintenance if implemented in a Matrix structure.

As matrices will, thus, be using a folded list of indices as per all other Matrix functions thus far, it is reasonable to request that this is done to maintain consistency throughout the library.

This is a non-breaking change, and must not modify any use of interfaces at a higher level of abstraction than EmuMath::Helpers::_vector_underlying.