Skip to content
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

chore: Remove catch-all overload of OStaticStream #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bnbajwa
Copy link
Contributor

@bnbajwa bnbajwa commented Jan 27, 2025

This an issue because if we attempt to create an custom overloaded operator<< for OStaticStream then it results in ambiguous call compiler error as there are now 2 valid overloads (first is catch-all in toolbox, and 2nd our custom defined one).

The catch-all overload mainly exists to ensure that after several streaming operations, OStaticStream& (ref) is returned. This then allows the OStaticStream& to be implicity converted to a string. For example, consider an expression like so: err_msg() << a << b << c;

If the catch-all overload did not exist, then this expression would return a 'std::ostream&' rather than 'OStaticStream&'. This would prevent the stream from being turned into a string implicitly as std::ostream& is not implicitly convertible to a string_view.

It is only 'err_msg()' that relies on this behaviour. Thus, 'ErrMsg' has now been promoted to a strong type, and implements the functionality it requires rather than burdening a generic type like OStaticStream. And so, the catch-all overload of OStaticStream, as well as implicit conversion to string_view can be removed.

SDB-8506

This an issue because if we attempt to create an overloaded operator<<
for a custom type then it results in ambiguous call compiler error as
there are now 2 valid overloads (first is catch-all in toolbox, and 2nd
our custom defined one).

The catch-all overload mainly exists to ensure that after several
streaming operations, OStaticStream& (ref) is returned. This then allows
the OStaticStream& to be implicity converted to a string. For example,
consider an expression like so: err_msg() << a << b << c;

If the catch-all overload did not exist, then this expression would
return a 'std::ostream&' rather than 'OStaticStream&'. This would
prevent the stream from being turned into a string implicitly as
std::ostream& is not implicitly convertible to a string_view.

It is only 'err_msg()' that relies on this behaviour. Thus, 'ErrMsg'
has been promoted to a strong type, and implements the functionality
it requires rather than burdening a generic type like OStaticStream.
And so, the catch-all overload of OStaticStream, as well as implicit
conversion to string_view can be removed.

SDB-8506
@bnbajwa bnbajwa requested a review from a team as a code owner January 27, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants