Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it well-formed to overload an operator for a standard-defined type in global namespace that doesn't depend on a user-define type? [duplicate]

Is the following code well-formed program per the standard?

std::ostream& operator<<(std::ostream& out, std::chrono::system_clock::time_point tp)
{
    return out << tp.time_since_epoch().count();
}

This isn't a template defined in the standard library, and isn't defined inside the namespace std, so it seems to be well-formed, but I might me missing something.

like image 442
Mário Feroldi Avatar asked Jan 29 '26 17:01

Mário Feroldi


1 Answers

I don't see anything in the section named Constraints on programs that forbids defining a function like yours.

I say, it is perfectly valid to do so.

like image 191
R Sahu Avatar answered Jan 31 '26 05:01

R Sahu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!