06 2019 档案
摘要:std::function 是 C++11 引入的通用可调用对象包装器, 它可以统一存储、传递和调用各种可调用对象(函数、lambda、成员函数、绑定表达式等),是实现回调、事件系统、函数式编程的核心工具。 1. 包装普通函数 double add(double a, double b) { ret
阅读全文
摘要:std::wstring主要用于 UTF-16编码的字符, std::string主要用于存储单字节的字符( ASCII字符集 ),但是也可以用来保存UTF-8编码的字符。 UTF-8和UTF-16是UNICODE字符集的两种不同的字符编码。 std::string ws2s(const std::
阅读全文
摘要:模板类函数 1.01 std::is_floating_point std::is_floating_point是C++11新增加的类型特征模板之一,它用于判断一个类型是否是浮点类型。它包含在头文件<type_traits>中。 通过在模板函数中使用std::is_floating_point来判断
阅读全文
摘要:std::async 是 C++11 提供的高级异步操作接口,用于启动一个异步任务,并自动返回一个 std::future 来获取结果。 #include <future> #include <iostream> int heavy_computation() { std::this_thread:
阅读全文
摘要:std::condition_variable 是 C++11 引入的同步原语, 它用于线程间通信,允许一个或多个线程等待某个条件成立,直到另一个线程发出通知。 它是实现生产者-消费者模型、任务队列、事件等待等多线程模式的核心工具。 条件变量本身不存储状态,它只是一个“通知机制”。 它必须与 std
阅读全文
摘要:std::this_thread::yield(): 当前线程放弃执行,操作系统调度另一线程继续执行。 区别 std::this_thread::sleep_for(): 表示当前线程休眠一段时间,休眠期间不与其他线程竞争CPU,根据线程需求,等待若干时间。 #include <iostream>
阅读全文
摘要:boost::static_visitor 是 Boost.Variant 库中的一个辅助类,用于定义 访问者(visitor),以便在 boost::variant 类型上执行 静态多态操作。 它允许你安全地对变体(variant)中存储的不同类型进行不同的处理,避免了复杂的 if-else 或类
阅读全文
摘要:std::optional 是 C++17 引入的一个容器类模板,用于表示一个值可能存在,也可能不存在。 它提供了一种类型安全的方式来处理“可空值”(nullable value),避免使用 nullptr、特殊值(如 -1)或 bool、value 的笨拙方式。 std::optional<T>
阅读全文
摘要:1.01 双缓冲 (Double Buffering) 防闪烁 在 QWidget 的 paintEvent() 中,直接绘制到屏幕可能导致闪烁。 使用 双缓冲技术:先将所有内容绘制到一个离屏的 QPixmap 或 QImage 上,然后在 paintEvent 的最后,将这个完整的图像一次性绘制到
阅读全文
摘要:#include <initializer_list> template <class T> class initializer_list; initializer_list对象中的元素永远是常量值const T,不能对initializer_list对象中元素的值修改 使用场景 1、可以使用初始化
阅读全文
摘要:std::decltype decltype ( 实体 ) decltype ( 表达式 ) 若实参是其他类型为 T 的任何表达式,且 a) 若 表达式 的值类别为亡值,则 decltype 产生 T&&; b) 若 表达式 的值类别为左值,则 decltype 产生 T&; c) 若 表达式 的值
阅读全文
摘要:auto 1.0 定义变量时,必须初始化 auto a = 10; // 正确 auto b; // 错误 1.1 不能用于函数参数 void func(auto a = 1); // 错误 1.2 不能用于函数参数 struct Foo { auto var1_ = 0; // error: au
阅读全文
摘要:环境:win10 vs2017 c++17 boost 1、下载源码:https://github.com/qicosmos/iguana 2、创建工程,包含源码目录、boost库目录;boost库;c++17 //json结构模板 struct person { std::string name;
阅读全文
摘要:cinatra 一个高效易用的c++ http框架 1、下载源码 https://github.com/qicosmos/cinatra 2、 准备好boost库 (vs2019 编译boost库 【msvc-14.2】 x64位) 3、 vs2019 配置工程: c++17 、boost路径、库路
阅读全文
摘要:环境: win10 vs2017 v141 1、下载 boost_1_70_0.zip. 2、以管理员方式打开 3、 bootstrap.bat 4、编译64位库 b2.exe stage --toolset=msvc-14.1 address-model=64 --stagedir="D:\App
阅读全文
摘要:基础操作 1.0 Pod /* 获取命名空间 */ kubectl get namespace /* 创建命名空间 */ kubectl create ns test /* 删除命名空间 */ kubectl delete ns test /* 使用yml文件 */ kubectl apply -f
阅读全文
摘要:Kuboard 搭建k8s 官网教程:https://kuboard.cn/ https://kuboard.cn/install/history-k8s/install-k8s-1.19.x.html 1.0 环境配置 # 修改 hostname hostnamectl set-hostname
阅读全文
摘要:1.01 事件 // main.cpp #include <SDL.h> #include <iostream> #define MY_EVENT_TYPE 10000 int main(int argc, char* argv[]) { // 1. 初始化SDL if (SDL_Init(SDL_
阅读全文
摘要:https://wiki.libsdl.org/SDL3/FrontPage 1.01 创建窗口/绘图 #include <SDL.h> #include <iostream> int main(int argc, char* argv[]) { // 1. 初始化SDL if (SDL_Init(
阅读全文
浙公网安备 33010602011771号