-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Issues with overloading by return type #175
Comments
Have just met another Case 3:
doesn't compile because of ambiguous call. |
Thank you for the feedback! That being said, I realize that the current state of things can be confusing and frustrating. My apologies! There's a few things that we can do to improve things. The ambiguity tends to happen in 3 classes of usage:
namespace rtm
{
template<typename rhs_t>
RTM_DISABLE_SECURITY_COOKIE_CHECK RTM_FORCE_INLINE vector4f RTM_SIMD_CALL vector_mul(vector4f_arg0 lhs, const rhs_t& rhs) RTM_NO_EXCEPT
{
return vector_mul(lhs, static_cast<scalarf>(rhs));
}
} This would resolve overload ambiguity while maintaining the API consistent. It would also allow user types to be used with RTM if they can coerce. The only other alternative I can think of would be to mark some return coercion statements as being I'll see what I can do with this for v2.3 early next year. I'm currently busy finishing up the next release of ACL this month but I hope to quickly release an RTM update next year with a few improvements. |
Speaking of these usage classes:
|
Hmm I'm not super happy with how this is turning out... Implicit coercion does not allow chaining user-defined conversions: only one is attempted (as per the standard). That prevents me from using template logic to explicitly define a coercion priority (by inserting dummy types that coerce into one another). Adding explicit coercion is ugly. It forces a different syntax and because it only works with direct initialization (can't use I think if we have to change the syntax to have only one coercion to float that is automatic, I would rather add functions on the return structs to clarify rather than rely on explicit coercion (e.g. |
I've given this quite a bit of thought over the past few weeks, and in the end I think some overloaded return types may have to go. While I personally love them and they work great for my programming style, I think that may be more of a niche. I'll break down my reasoning as follows:
To that end, I think the best course of action may be to introduce new functions with a suffix to clarify usage and intent:
I think a more verbose suffix makes sense for clarity. I fear that something more compact like However, some return based overloads will remain:
Functions that have a scalar based overload will return a scalar automatically without a suffix (e.g. How does that sound? Let me know what you think. I intent to move forward with this and finish up the 2.3 release shortly (this is the last task for it). |
I think that's OK to have a function with a short name for the logically expected case and a function with postfix for an opposite case. I.e. it is expected for |
I'll deprecate what I can for this release. This is likely to generate warnings with ACL until its next release. To that end, I'm adding |
Hi! Just updated from ACL 1.3 to latest version with RTM 2.2.0. I have been using ACL math for my own code outside animation system, and there are a couple of issues which are noticeable after porting.
Case 1
produces following errors:
Case 2
float MaxDim = std::max({ rtm::vector_get_x(BoxExtent), rtm::vector_get_y(BoxExtent), rtm::vector_get_z(BoxExtent) });
(BTW can I do horizontal max better with RTM?)
and
std::max(rtm::vector_distance3(_EyePos, Record.BoxCenter), 1.0f)
now fail to choose the same type for all arguments.
Case 2 is fixed trivially with
std::max<float>(...)
. Case 1 requires more verbose fix:or
Maybe you have an idea how to improve default behaviour? As far as I understand, overloading by return type is a feature that reduces necessity of explicit casts, but here it does the opposite thing.
MSVC 2022 17.7.6
Windows 11
The text was updated successfully, but these errors were encountered: