units icon indicating copy to clipboard operation
units copied to clipboard

Incomplete constexpr support

Open JohelEGP opened this issue 7 years ago • 1 comments

Greetings.

I tried using some units in a constexpr context and found that constexpr is partially supported. Here's an extract of what I tried to run, with the operations that lack constexpr support commented out.

constexpr void test_constexpr()
{
    using namespace units::literals;

    units::length::meter_t m{42};
    //    +m;
    //    -m;
    //    ++m;
    //    --m;
    //    m++;
    //    m--;
    m + m;
    m - m;
    m * 42;
    42 * m;
    m / 42;
    m / m;
    //    m += 42_m;
    //    m -= 42_m;
    //    m *= 42;
    //    m /= 42;
}

I tested this on the branch v3.x. The library uses C++17 in some places, so I suggest improving the constexpr support, which should be doable even with C++14. I did check some of the operation's implementations, and sprinkling constexpr should do the job. I didn't check the support for the dimensional-analysis operators nor the cmath's-like operations.

JohelEGP avatar May 02 '18 22:05 JohelEGP

looks like an oversight when I added those operators. The dimensional analysis should all be constexpr, but if you find holes obviously let me know.

The cmath functions, aside from specialized pow/sqrt, are not constexpr, because right now they are ADL wrappers on top of the actual cmath functions, which are not constexpr as of c++17. I've been looking for a good constexpr cmath library to pull in, but haven't settled on anything yet.

nholthaus avatar May 02 '18 23:05 nholthaus