• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <chrono>

    std::chrono::operator+

    namespace std::chrono {
      constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; // (1) C++20
      constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; // (2) C++20
    
      constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;  // (3) C++20
      constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;  // (4) C++20
    }
    

    概要

    year_monthの加算を行う。

    • (1) : year_monthに月の時間間隔を加算する
    • (2) : 月の時間間隔にyear_monthを加算する
    • (3) : year_monthに年の時間間隔を加算する
    • (4) : 年の時間間隔にyear_monthを加算する

    テンプレートパラメータ制約

    • (1), (2) : monthsパラメータに指定した引数がyearsに変換可能である場合、yearsへの暗黙変換は、monthsへの暗黙変換よりも劣る

    戻り値

    • (1) : 以下の式がtrueとなるyear_monthオブジェクトzを返す

      z.ok() && z - ym == dm;
      

    • (2) :

      return ym + dm;
      

    • (3) :

      return (ym.year() + dy) / ym.month();
      

    • (4) :

      return ym + dy;
      

    計算量

    • (1) : dmの値に関してO(1)

    例外

    投げない

    #include <cassert>
    #include <chrono>
    
    namespace chrono = std::chrono;
    using namespace std::chrono_literals;
    
    int main()
    {
      assert(2020y/3 + chrono::months{1} == 2020y/4);
      assert(2020y/3 + chrono::years{1} == 2021y/3);
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    参照