nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
938 stars 134 forks source link

Implicit conversions don't work both ways #235

Open deathwishdave opened 4 years ago

deathwishdave commented 4 years ago

Version v2.3.1, on GNU++17

#include <iostream>

#include "units.h"

int main(int argc, const char * argv[])
{
    {
        long double one = 1.0;

        units::time::second_t seconds;
        units::time::minute_t minutes(one);

        seconds = minutes;

        std::cout << "1 minute is " << seconds << std::endl;
    }

    {
        long double one = 1.0;

        units::time::second_t seconds(one);
        units::time::minute_t minutes;

        minutes = seconds;

        std::cout << "1 second is " << minutes << std::endl;
    }

    return 0;
}

produces

1 minute is 60 s 1 second is 1 s

burnpanck commented 4 years ago

They do:

std::cout << "1 second is " << minutes.to<double>() << " min" << std::endl;

produces

1 second is 1.0 min

What doesn't work properly is streaming to io-streams, see #228.