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
947 stars 135 forks source link

Inconsistency with Streaming and Strings #228

Closed parnmatt closed 1 year ago

parnmatt commented 5 years ago

units 2.3.1 gcc 8.2.1

I've noticed an inconsistency with streaming out and string conversions

std::cout << 3_yr << '\n' << units::time::to_string(3_yr) << '\n';
9.4608e+07 s
3 yr

The latter, having to use the to_string function in the correct namespace is a bit of pain.

template <class Units, typename T, template<typename> class NonLinearScale>
inline std::ostream& units::operator<<(std::ostream&, units::unit_t<Units, T, NonLinearScale> const&) noexept;

reference; and,

inline std::ostream& units::time::operator<<(std::ostream&, units::time::year_t const&)noexept;

reference.

it seems that the templated version takes precedence. My understanding of overloads, the latter should be chosen; but I believe being in a different namespace ADL took a different path?

Either way; I think it makes sense to print "exact types" as they are; but perhaps "undefined types" like in a calculation, as their SI bases.

nholthaus commented 3 years ago

The library as a whole is over-namspaced in 2.3, in a way that breaks ADL. I think we should look at moving all non-member functions into the units namepsace, and possibly all unit definitions.

nholthaus commented 1 year ago

fixed in 3.x