• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <chrono>

    std::chrono::abs

    namespace std::chrono {
      template <class Rep, class Period>
      constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
    }
    

    概要

    絶対値を求める。

    戻り値

    return d >= d.zero() ? d : -d;
    

    備考

    #include <iostream>
    #include <chrono>
    
    using namespace std::chrono;
    
    int main()
    {
      seconds s{-123};
      seconds result = abs(s);
    
      std::cout << result.count() << std::endl;
    }
    

    出力

    123
    

    バージョン

    言語

    • C++17

    処理系

    参照