Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::chrono::operator+,std::chrono::operator-(std::chrono::weekday)

      From cppreference.com
      <cpp‎ |chrono‎ |weekday
       
       
      Date and time library
       
       
      Defined in header<chrono>
      constexprstd::chrono::weekday operator+(conststd::chrono::weekday& wd,
                                               conststd::chrono::days& d)noexcept;
      (1)(since C++20)
      constexprstd::chrono::weekday operator+(conststd::chrono::days& d,
                                               conststd::chrono::weekday& wd)noexcept;
      (2)(since C++20)
      constexprstd::chrono::weekday operator-(conststd::chrono::weekday& wd,
                                               conststd::chrono::days& d)noexcept;
      (3)(since C++20)
      constexprstd::chrono::days operator-(conststd::chrono::weekday& wd1,
                                             conststd::chrono::weekday& wd2)noexcept;
      (4)(since C++20)
      1,2) Addsd.count() days towd. The weekday value held in the result is computed by first evaluatingstatic_cast<longlong>(wd.c_encoding())+ d.count() and reducing it modulo 7 to an integer in the range[06].
      3) Subtractsd.count() days fromwd. Equivalent toreturn wd+-d;.
      4) Ifwd1.ok() andwd2.ok() are bothtrue, returns astd::chrono::days valued such thatd.count() is in the range[06] andwd2+ d== wd1. Otherwise the returned value is unspecified.

      Contents

      [edit]Return value

      1-3) Astd::chrono::weekday holding a weekday value calculated as described above.
      4) Astd::chrono::days representing the distance betweenwd1 andwd2.

      [edit]Notes

      As long as the computation doesn't overflow,(1-3) always return a validweekday even ifwd.ok() isfalse.

      [edit]Example

      Run this code
      #include <chrono>#include <iostream> int main(){std::cout<<std::boolalpha; std::chrono::weekday wd{4};    wd= wd+std::chrono::days(2);std::cout<<(wd==std::chrono::weekday(6))<<' '<<(wd==std::chrono::Saturday)<<' ';     wd= wd-std::chrono::days(3);std::cout<<(wd==std::chrono::weekday(3))<<' '<<(wd==std::chrono::Wednesday)<<' ';     wd=std::chrono::Tuesday;    wd= wd+std::chrono::days{8};// (((2 + 8) == 10) % 7) == 3;std::cout<<(wd==std::chrono::Wednesday)<<' ';     wd= wd+(std::chrono::Sunday-std::chrono::Thursday);// (3 + 3) == 6std::cout<<(wd==std::chrono::Saturday)<<'\n';}

      Output:

      true true true true true true

      [edit]See also

      increments or decrements the weekday
      (public member function)[edit]
      adds or subtracts a number of days
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/weekday/operator_arith_2&oldid=157509"

      [8]ページ先頭

      ©2009-2026 Movatter.jp