std::chrono::time_point::max

来自cppreference.com
< cpp‎ | chrono‎ | time point
 
 
工具库
类型支持(基本类型、 RTTI 、类型特性)
动态内存管理
错误处理
程序工具
变参数函数
日期和时间
函数对象
(C++11)
关系运算符
optionalanyvariant (C++17)
pair 与 tuple
(C++11)
(C++17)
swap 、 forward 与 move
(C++14)
(C++11)
(C++11)
初等字符串转换
(C++17)
(C++17)
类型运算
(C++11)
(C++17)
 
 
 
static constexpr time_point max();

返回拥有最大可能时长的 time_point ,即 std::chrono::time_point(std::chrono::duration::max())

[编辑] 参数

(无)

[编辑] 返回值

最大的可能的 time_point

[编辑] 示例

#include <chrono>
#include <vector>
#include <iostream>
 
int main() 
{
    std::chrono::time_point<std::chrono::system_clock> now =
        std::chrono::system_clock::now();
    std::vector<std::chrono::time_point<std::chrono::system_clock>> times {
        now - std::chrono::hours(24),
        now - std::chrono::hours(48),
        now + std::chrono::hours(24),
    };  
 
    std::chrono::time_point<std::chrono::system_clock> earliest =
        std::chrono::time_point<std::chrono::system_clock>::max();
 
    std::cout << "all times:\n";
    for (const auto &time : times) {
        std::time_t t = std::chrono::system_clock::to_time_t(time);
        std::cout << std::ctime(&t);
 
        if (time < earliest) earliest = time;
    }
 
    std::time_t t = std::chrono::system_clock::to_time_t(earliest);
    std::cout << "earliest:\n" << std::ctime(&t);
}

可能的输出:

all times:
Sun Oct  7 19:06:48 2012
Sat Oct  6 19:06:48 2012
Tue Oct  9 19:06:48 2012
earliest:
Sat Oct  6 19:06:48 2012