Skip to content

Conversation

@chiphogg
Copy link
Member

@chiphogg chiphogg commented Aug 7, 2025

Sometimes, end users have aliases for Quantity or QuantityPoint
types. In these cases, sticking exclusively to .as can be more
awkward than just using a constructor. Therefore, we add new Q-to-Q
(and QP-to-QP) constructors to support a second policy argument.

Follow-on for #387.

Sometimes, end users have aliases for `Quantity` or `QuantityPoint`
types.  In these cases, sticking exclusively to `.as` can be more
awkward than just using a constructor.  Therefore, we add new Q-to-Q
(and QP-to-QP) constructors to support a second policy argument.

Follow-on for #387.
Copy link
Contributor

@geoffviola geoffviola left a comment

Choose a reason for hiding this comment

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

The changes look good. Thanks for cleaning that up.

sticking exclusively to .as can be more
awkward than just using a constructor.

What's the guidance there? Use fewer characters? 😁

@chiphogg
Copy link
Member Author

chiphogg commented Aug 7, 2025

What's the guidance there? Use fewer characters? 😁

Well, I won't complain about fewer characters! But I think of it more in terms of reducing complexity.

Example: we had one usage like this:

seconds_{value.template as<typename second_t::Rep>(seconds, ignore(TRUNCATION_RISK))},

where the type of the seconds_ member was the second_t alias. Of course, this is really equivalent to:

seconds_{value.template as<typename second_t::Rep>(typename second_t::Unit, ignore(TRUNCATION_RISK))},

So, we're kind of awkwardly recreating the target type second_t in a roundabout way. This both obscures intent, and creates opportunity for error and/or reader uncertainty.

This change allows us to write this instead:

seconds_{value, ignore(TRUNCATION_RISK)},

In fact, this example shows that this change is helpful for more than just alias use cases, because nothing about this final form depends on the fact that we used an alias to declare the seconds_ member variable.

@chiphogg chiphogg merged commit 2f32834 into main Aug 7, 2025
14 checks passed
@chiphogg chiphogg deleted the chiphogg/policy-constructors#387 branch August 7, 2025 14:20
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.

3 participants