std::chrono::ambiguous_local_time
来自 cppreference.cn
定义于头文件 <chrono> |
||
class ambiguous_local_time; |
(C++20 起) | |
定义一种对象类型,当尝试将模棱两可的 std::chrono::local_time 转换为 std::chrono::sys_time 而未指定 std::chrono::choose(例如 choose::earliest
或 choose::latest
)时,作为异常抛出。
此异常由 std::chrono::time_zone::to_sys 以及调用它的函数(例如接受 std::chrono::local_time 的 std::chrono::zoned_time 的构造函数)抛出。
继承图
目录 |
[编辑] 成员函数
(构造函数) |
构造异常对象 (公开成员函数) |
operator= |
替换异常对象 (公开成员函数) |
what |
返回解释字符串 (公开成员函数) |
std::chrono::ambiguous_local_time::ambiguous_local_time
template< class Duration > ambiguous_local_time( const std::chrono::local_time<Duration>& tp, |
(1) | (C++20 起) |
ambiguous_local_time( const ambiguous_local_time& other ) noexcept; |
(2) | (C++20 起) |
构造异常对象。
1) what() 返回的解释字符串等同于以下代码产生的 os.str()
std::ostringstream os; os << tp << " is ambiguous. It could be\n" << tp << ' ' << i.first.abbrev << " == " << tp - i.first.offset << " UTC or\n" << tp << ' ' << i.second.abbrev << " == " << tp - i.second.offset << " UTC";
如果 i.result != std::chrono::local_info::ambiguous,则行为未定义。
2) 拷贝构造函数。如果 *this 和
other
都具有动态类型 std::chrono::ambiguous_local_time
,则 std::strcmp(what(), other.what()) == 0。参数
tp | - | 尝试转换的时间点 |
i | - | 描述转换结果的 std::chrono::local_info |
其他 | - | 另一个要拷贝的 ambiguous_local_time |
异常
可能抛出 std::bad_alloc
注意
因为不允许拷贝派生自 std::exception 的标准库类抛出异常,所以此消息通常作为单独分配的引用计数字符串内部存储。
std::chrono::ambiguous_locale_time::operator=
ambiguous_locale_time& operator=( const ambiguous_locale_time& other ) noexcept; |
(C++20 起) | |
用 other 的内容赋值。如果 *this 和 other 都具有动态类型 std::chrono::ambiguous_locale_time
,则赋值后 std::strcmp(what(), other.what()) == 0。
参数
其他 | - | 用于赋值的另一个异常对象 |
返回值
*this
std::chrono::ambiguous_locale_time::what
virtual const char* what() const noexcept; |
(C++20 起) | |
返回解释字符串。
返回值
指向实现定义的空终止字符串的指针,其中包含解释性信息。该字符串适合转换为 std::wstring 并显示。保证该指针至少在获取它的异常对象被销毁之前,或在异常对象上调用非 const 成员函数(例如拷贝赋值运算符)之前有效。
在常量求值期间,返回的字符串使用普通字面量编码进行编码。 |
(C++26 起) |
注意
允许但不要求实现重写 what()
。
继承自 std::exception
成员函数
[virtual] |
销毁异常对象 ( std::exception 的虚公共成员函数) |
[virtual] |
返回解释字符串 ( std::exception 的虚公共成员函数) |
[编辑] 另请参阅
(C++20) |
报告本地时间不存在时抛出的异常 (类) |