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

Improve genericity by removing the namespace `math`. #145

Closed le-migou closed 6 years ago

le-migou commented 6 years ago

Let's say I'm building the following generic library

    template <class T> void
f (T x)
{
    sqrt (x);
}

. Using it with units won't work because the sqrt function is in the namespace math and ADL will not find it.

int main ()
{
    using namespace units::literals;
    f (1);
    f (1_K); // <- Error: no matching call to sqrt.
}

. Putting all the math overloaded functions in the namespace of unit_t is the way to go in order for ADL to work. (See recommendations C.5 and C.168 of the Core Guidelines.) So I propose to remove the namespace math entirely.

nholthaus commented 6 years ago

100% right. This has already been corrected in the v3.x development. No plans to change namespacing in the 2.x line.

You may want to try out v3 alpha 2. It's more stable than the name implies and has a lot of improvements for generality and sfinae friendliness, although we still have a way to go.