1 Star 0 Fork 0

Liccsu/TinyWebServer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Fmt.hpp 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
/*
* Copyright (c) -2024
* Liccsu
* All rights reserved.
*
* This software is provided under the terms of the GPL License.
* Please refer to the accompanying LICENSE file for detailed information.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GPL License for more details.
*
* For further inquiries, please contact:
* liccsu@163.com
*/
#ifndef TINYWEBSERVER_FMT_HPP
#define TINYWEBSERVER_FMT_HPP
#include <cstdio>
#include <type_traits>
#include <utility>
class Fmt {
char buf_[64]{};
size_t length_;
public:
template<typename T>
[[maybe_unused]]
Fmt(const char *format, T &&value) {
static_assert(std::is_arithmetic_v<T>, "Must be arithmetic type");
length_ = std::snprintf(buf_, sizeof(buf_), format, std::forward<T>(value));
}
[[nodiscard]]
const char *data() const {
return buf_;
}
[[nodiscard]]
size_t length() const {
return length_;
}
};
#endif //TINYWEBSERVER_FMT_HPP
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Liccsu/TinyWebServer.git
git@gitee.com:Liccsu/TinyWebServer.git
Liccsu
TinyWebServer
TinyWebServer
master

搜索帮助