1. 6
    1. 3

      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

      1. 8

        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).

        1. 6

          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.

        2. 3

          How does it hide control flow? An operator is just a different way to write a function.

      2. 2

        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.

      3. [Comment removed by author]

    2. 1

      Could you combine it with user-defined literals like 2021_year and 23_day for even more suffering fun?

    3. 1

      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:

      std::chrono::year_month(y, m)
      std::chrono::year_month(y, std::chrono::month(m))
      std::chrono::month_day(m, d)
      std::chrono::month_day(m, std::chrono::day(d))
      std::chrono::month_day(std::chrono::month(m), d)
      std::chrono::month_day_last(m)
      std::chrono::month_day_last(std::chrono::month(m))
      std::chrono::month_weekday(m, wdi)
      std::chrono::month_weekday(std::chrono::month(m), wdi)
      std::chrono::month_weekday_last(m, wdl)
      std::chrono::month_weekday_last(std::chrono::month(m), wdl)
      std::chrono::year_month_day(ym.year(), ym.month(), d)
      std::chrono::year_month_day(ym.year(), ym.month(), std::chrono::day(d))
      std::chrono::year_month_day(y, md.month(), md.day())
      std::chrono::year_month_day(std::chrono::year(y), md.month(), md.day())
      std::chrono::year_month_day_last(ym.year(), std::chrono::month_day_last(ym.month()))
      std::chrono::year_month_day_last(y, mdl)
      std::chrono::year_month_day_last(std::chrono::year(y), mdl)
      std::chrono::year_month_weekday(ym.year(), ym.month(), wdi)
      std::chrono::year_month_weekday(y, mwd.month(), mwd.weekday_indexed())
      std::chrono::year_month_weekday(std::chrono::year(y), mwd.month(), mwd.weekday_indexed())
      std::chrono::year_month_weekday_last(ym.year(), ym.month(), wdl)
      std::chrono::year_month_weekday_last(y, mwdl.month(), mwdl.weekday_last())
      std::chrono::year_month_weekday_last(std::chrono::year(y), mwdl.month(), mwdl.weekday_last())
      

      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.

      1. 1

        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?

        1. 2

          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.

        2. 2

          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.

        3. 1

          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”.