mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
1.07k stars 85 forks source link

extracting joule from watt multiplied by seconds #512

Closed magni-mar closed 3 months ago

magni-mar commented 11 months ago

Got this bug while developing and wondering weather this is possible using mp-units v2.

When multiplying watt and seconds I am not able to place it into a variable that is designated as joule, is there a way around this?

#include <mp-units/systems/si/units.h>
#include <mp-units/systems/cgs/cgs.h>

auto main(int argc, char *argv[]) -> int {

    using namespace mp_units;

    quantity<si::watt> motor_power{4000 * si::watt};
    quantity<cgs::second> mix_time{60 * cgs::second};
    quantity<si::joule> motor_energy{motor_power * mix_time};

    return EXIT_SUCCESS;
}

the code above produces the error:

error: no matching function for call to ‘mp_units::quantity<mp_units::si::joule()>::quantity(<brace-enclosed initializer list>)’
   10 |     quantity<si::joule> motor_energy{motor_power * mix_time};
      |                                                            ^
mpusz commented 11 months ago

Thanks for reporting this bug. I am now on an extended vacation, but I will try to fix it when I find some time.

magni-mar commented 10 months ago

To be noted, using mp_units::si::seconds this works, but not using mp_units::cgs::second

mpusz commented 10 months ago

Yes, I know. I was able to reproduce it, and I know now what the problem is. I just did not have time to try to fix it, as I spent all of my recent time writing ISO proposals and refactoring quantity points. I promise I will come back to it when I have a bit more time. Again, sorry that it takes so long to resolve.

magni-mar commented 10 months ago

No problem I just wanted to note this for outside observers because I just discovered that I was using 2 different systems