Console Library 4.7.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
literals.h
Go to the documentation of this file.
1
10
11/*
12Copyright (c) 2026 MrXie1109
13
14Permission is hereby granted, free of charge, to any person obtaining a copy
15of this software and associated documentation files (the "Software"), to deal
16in the Software without restriction, including without limitation the rights
17to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18copies of the Software, and to permit persons to whom the Software is
19furnished to do so, subject to the following conditions:
20
21The above copyright notice and this permission notice shall be included in all
22copies or substantial portions of the Software.
23
24THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30SOFTWARE.
31*/
32
33#pragma once
34#include "strpp.h"
35#include "time.h"
36
42namespace console
43{
44 namespace literals
45 {
46 // ---------------------------- 时间字面量(整数版本)----------------------------
52 Time operator""_ns(unsigned long long ns)
53 {
54 return Time(ns);
55 }
56
62 Time operator""_us(unsigned long long us) { return Time(us * 1e3); }
63
69 Time operator""_ms(unsigned long long ms) { return Time(ms * 1e6); }
70
76 Time operator""_s(unsigned long long s) { return Time(s * 1e9); }
77
83 Time operator""_min(unsigned long long min) { return Time(min * 6e10); }
84
90 Time operator""_hr(unsigned long long hr) { return Time(hr * 3.6e12); }
91
92 // ---------------------------- 时间字面量(浮点数版本)----------------------------
98 Time operator""_ns(long double ns) { return Time(ns); }
99
105 Time operator""_us(long double us) { return Time(us * 1e3); }
106
112 Time operator""_ms(long double ms) { return Time(ms * 1e6); }
113
119 Time operator""_s(long double s) { return Time(s * 1e9); }
120
126 Time operator""_min(long double min) { return Time(min * 6e10); }
127
133 Time operator""_hr(long double hr) { return Time(hr * 3.6e12); }
134
135 // ---------------------------- 格式化字符串字面量 ----------------------------
143 f_string operator""_f(const char *str, size_t) { return str; }
144 }
145}
表示以纳秒为单位的时间量,支持单位转换、算术运算和自动选择合适的输出单位。
Definition time.h:52
格式化字符串类,支持使用 % 运算符进行占位符 {} 替换。
Definition strpp.h:302
T min(const MultiArray< T, Dims... > &a)
求最小值。
Definition multiarray.h:1551
包含自定义字面量运算符的命名空间。
本库所有组件所在的顶层命名空间。
提供字符串处理工具函数和格式化类。
提供时间度量、计时、休眠和日期时间格式化功能。