Skip to content

Conversation

@chiphogg
Copy link
Member

@chiphogg chiphogg commented May 2, 2025

Consider the following three options for creating a unit of squared
nanoseconds:

using NanoSecondsSquared = decltype(squared(Nano<Seconds>{}));
using NanoSecondsSquared = UnitPowerT<Nano<Seconds>, 2>;
using NanoSecondsSquared = Squared<Nano<Seconds>>;

The third one is the most appealing, but it doesn't currently exist.
This PR adds it.

Includes docs.

Fixes #397.

Consider the following three options for creating a unit of squared
nanoseconds:

```cpp
using NanoSecondsSquared = decltype(squared(Nano<Seconds>{}));
using NanoSecondsSquared = UnitPowerT<Nano<Seconds>, 2>;
using NanoSecondsSquared = Squared<Nano<Seconds>>;
```

The third one is the most appealing, but it doesn't currently exist.
This PR adds it.

Includes docs.

Fixes #397.
return root<2>(x);
}
template <typename T>
using Sqrt = decltype(sqrt(std::declval<T>()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broader question: Is this the name we want to use for these helpers. I know when I see cbrt I have to look up what that means. Our API is pretty fluent, so SquareRoot and CubeRoot wouldn't really be out of place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I think so?

The argument for the status quo is that cbrt should be consistent with std::cbrt, so we make Cbrt consistent with cbrt. This makes it easier for people to "guess" the rest if they know any of them.

I do agree that for type names, CubeRoot<Nano<Liters>> would be nicer than Cbrt<Nano<Liters>> in a lot of ways, but for now at least I'm finding the consistency argument more persuasive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. The lower case matching up is obviously plays well with std. And I don't think we should be polluting the namespace with a bunch of aliases. Projects can always provide their own alias if desired.

@chiphogg chiphogg requested a review from hoffbrinkle May 2, 2025 16:26
@chiphogg chiphogg merged commit 4019559 into main May 2, 2025
15 checks passed
@chiphogg chiphogg deleted the chiphogg/type-based-aliases#397 branch May 2, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support "type versions" of squared, sqrt, etc.

3 participants