-
Notifications
You must be signed in to change notification settings - Fork 45
Use User-defined literals #2235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
00947be
a011bf6
92fe6aa
6c7e9a7
d8beeb2
3aff456
3aefebf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,34 +178,33 @@ CELER_ICC barn = Constant{1e-24} * centimeter * centimeter; | |
| * \endcode | ||
| * | ||
| * \note In headers, prefer explicit multiplication (e.g., \c 2.5 * | ||
| * units::centimeter) or bring in only the needed literal operator inside a | ||
| * function scope: | ||
| * units::centimeter) or bring the namespace inside a function scope: | ||
| * \code | ||
| * using celeritas::units::literals::operator"" _centimeter; | ||
| * using namespace celeritas::units::literals; | ||
| * return 2.5_centimeter; | ||
| * \endcode | ||
| */ | ||
| namespace literals | ||
| { | ||
|
|
||
| #define CELER_DEFINE_UNIT_UDL(SUFFIX, NAME) \ | ||
| CELER_CONSTEXPR_FUNCTION real_type operator""_##SUFFIX(long double v) \ | ||
| { \ | ||
| return static_cast<real_type>(v) * units::NAME; \ | ||
| } \ | ||
| CELER_CONSTEXPR_FUNCTION Constant operator""_##SUFFIX( \ | ||
| unsigned long long int v) \ | ||
| { \ | ||
| return v * units::NAME; \ | ||
| } \ | ||
| CELER_CONSTEXPR_FUNCTION real_type operator""_##NAME(long double v) \ | ||
| { \ | ||
| return static_cast<real_type>(v) * units::NAME; \ | ||
| } \ | ||
| CELER_CONSTEXPR_FUNCTION Constant operator""_##NAME( \ | ||
| unsigned long long int v) \ | ||
| { \ | ||
| return v * units::NAME; \ | ||
| #define CELER_DEFINE_UNIT_UDL(SUFFIX, NAME) \ | ||
| CELER_CONSTEXPR_FUNCTION double operator""_##SUFFIX(long double v) \ | ||
| { \ | ||
| return v * units::NAME; \ | ||
| } \ | ||
| CELER_CONSTEXPR_FUNCTION Constant operator""_##SUFFIX( \ | ||
| unsigned long long int v) \ | ||
| { \ | ||
| return v * units::NAME; \ | ||
| } \ | ||
| CELER_CONSTEXPR_FUNCTION double operator""_##NAME(long double v) \ | ||
| { \ | ||
| return v * units::NAME; \ | ||
| } \ | ||
| CELER_CONSTEXPR_FUNCTION Constant operator""_##NAME( \ | ||
| unsigned long long int v) \ | ||
| { \ | ||
| return v * units::NAME; \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot's gone crazy
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to return double (or long double if we care about it?) which matches the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment below: I think |
||
| } | ||
|
|
||
| CELER_DEFINE_UNIT_UDL(cm, centimeter) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.