I disagree. Language features that hide control flow and make things non-obvious such as changing the meaning of the division operator lean towards abuse over use, in my opinion. It’s not like the result looks particularly good from a syntactic perspective, either (imo).
This. It’s a cute trick but not one that is particularly more useful than auto ymd {2021, January, 23};, especially since there’s plenty of countries out there that tend to use things other than / as a date separator.
It’s nice syntax, but a bit over engineered IMO. How often does one need to construct Gregorian calendar dates this way? Regular struct declaration would look nearly as good.
The / operator for concatenating filesystem paths is great, though.
I think this is a very impressive use of operator overloading in C++. The only criticism I have is that it seems to be somewhat overengineered: would it not be simpler to just allow something like yyyy/mm/dd?
Now they had to introduce many possible combinations of ordering for questionable benefit:
I understand that everyone wants dd/mm/yyyy and US-Americans would like mm/dd/yyyy, so a good compromise may be to please nobody (like the UTC acronym) and keep code simpler.
I was taught all three were acceptable in my Turkish class (in a Turkish school (as a Turkish person (in Turkey))). So that’s at least two countries that use slashes as date separators.
That ordering (little endian, stashes as separators) is also common in the UK, though for any formal use I prefer the ISO ordering (big endian, hyphens as separators). As long as I don’t have to deal with the weird middle-endian US format, I’m happy.
A prime example of nice c++. Operator/ is also used as a path separator in std::filesystem: https://en.cppreference.com/w/cpp/filesystem/path/operator_slash
I disagree. Language features that hide control flow and make things non-obvious such as changing the meaning of the division operator lean towards abuse over use, in my opinion. It’s not like the result looks particularly good from a syntactic perspective, either (imo).
This. It’s a cute trick but not one that is particularly more useful than
auto ymd {2021, January, 23};
, especially since there’s plenty of countries out there that tend to use things other than/
as a date separator.How does it hide control flow? An operator is just a different way to write a function.
It’s nice syntax, but a bit over engineered IMO. How often does one need to construct Gregorian calendar dates this way? Regular struct declaration would look nearly as good.
The / operator for concatenating filesystem paths is great, though.
[Comment removed by author]
Could you combine it with user-defined literals like
2021_year
and23_day
for even moresufferingfun?I think this is a very impressive use of operator overloading in C++. The only criticism I have is that it seems to be somewhat overengineered: would it not be simpler to just allow something like
yyyy/mm/dd
?Now they had to introduce many possible combinations of ordering for questionable benefit:
I understand that everyone wants
dd/mm/yyyy
and US-Americans would likemm/dd/yyyy
, so a good compromise may be to please nobody (like theUTC
acronym) and keep code simpler.I thought that pretty much only US locale has / as date seperator (and we non-us peeps mainly use dot or dash). So that DD/mm/yyyy is monstrosity?
I was taught all three were acceptable in my Turkish class (in a Turkish school (as a Turkish person (in Turkey))). So that’s at least two countries that use slashes as date separators.
That ordering (little endian, stashes as separators) is also common in the UK, though for any formal use I prefer the ISO ordering (big endian, hyphens as separators). As long as I don’t have to deal with the weird middle-endian US format, I’m happy.
According to Wikipedia French dates are written as DD/mm/yyyy.
In informal usage in Sweden, the format DD/mm is sometimes used: “styrelsemötet är planerat till 7/5”.