forward std

std::for_each易忽略点

以下代码为修改vector内部的每一个元素,使其每个元素大小变为原来的平方。 std::vector v1{1, 2, 4, 2}; std::for_each(begin(v1), end(v1), [](auto& n) { return n * n; }); for (const auto& ......
for_each each std for

std模版库 队列、优先队列、双端队列

queue为单端队列 deque为双端队列 priority_queue为优先队列 #include #include priority_queue, less> // 最大堆 默认为对大堆 也即和 priority_queue 等价 priority_queue, greater> // 最小堆 ......
队列 模版 std

C++11 右值引用&&、移动语义std::move、完美转发std::forward

参考:https://blog.csdn.net/HR_Reborn/article/details/130363997 #pragma once class Array { public: Array() : size_(0), data_(nullptr){ } Array(int size) ......
语义 amp std forward move

c++ stl std::sort使用例子

class User { public: int32_t m_fight_power; private: int32_t m_level; }; bool CenterData::compare(const User *left, const User *right) { if(left->m_fi ......
例子 sort stl std

什么是企业管理软件的 Roll-forward update releases

`Roll-forward update releases`,也被称为“滚动前进式更新发布”,是软件开发和维护中的一种策略,旨在在系统更新过程中不仅修复问题,还在原有基础上添加新功能。这种策略强调在更新过程中不断“向前滚动”,持续提升系统的功能和性能,同时保持稳定性和兼容性。在企业级软件架构中,`r ......

std::allocator

设计主要目的:减少malloc的cookie的开销 设计主要方法:减少malloc的次数,用数据结构管理已经分配的内存。 核心数据结构:free_list[16]存储16根链表头,free_list[i],0~15 ,free_list[i]管理(i + 1)*16字节型区块。 客户所需要内存块大小 ......
allocator std

C++里std::enable_shared_from_this是干什么用的?

std::enable_shared_from_this使用场景 在很多场合,经常会遇到一种情况,如何安全的获取对象的this指针,一般来说我们不建议直接返回this指针,可以想象下有这么一种情况,返回的this指针保存在外部一个局部/全局变量,当对象已经被析构了,但是外部变量并不知道指针指向的对象 ......

C++ 多线程详解之异步编程 std::packaged_task

std::packaged_task 将任何可调用对象(比如函数、lambda 表达式等等)封装成一个 task,可以异步执行。执行结果可以使用 std::future 获取。 比如下面的例子,构造一个 std::packaged_task 后,get_future() 函数返回一个 std::fu ......
线程 packaged_task packaged task std

关于callback和std::bind的那些事

## 前言 使用callback常常需要绑定类的具体函数,哪些可以绑定哪些不能? ## 分析 callback不同与普通函数,其入参也是一个函数,具体行为由入参决定 我们看这样一段代码 https://godbolt.org/z/4YTKs567j ```cpp #include #include ......
callback bind std

关于 std::vector 容器初始化特殊长度导致的 Segmentation Fault 错误

当我们设置 std::vector 的长度时, 常这样书写: ```cpp std::vector vec(length); ``` 这样做一般不会出问题, 编译可正常通过, 然而当把 length 设置为 0 时, 执行有报错: ```bash Segmentation fault ``` 程序发 ......
Segmentation 容器 长度 错误 vector

c++ std::to_string实现原理

写这篇的起因是看到 MSVC STL 的一个[issue](https://github.com/microsoft/STL/issues/3857),里面提到```to_string```的实现,正常人的思维是直接除10拿到每位, 其实有个更高效的查表法 # 字符串转数字 除100拿到两位,并查表 ......
to_string 原理 string std to

std::condition_variable 练习(多线程任务序列化)

#include <functional> #include <map> #include <random> #include <chrono> #include <iostream> #include <format> #include <cmath> #include <thread> #inc ......

std::condition_variable 练习(多线程任务序列化)

#include <functional> #include <map> #include <random> #include <chrono> #include <iostream> #include <format> #include <cmath> #include <thread> #inc ......

C++ 字符串拼接技巧(stringstream、字符串迭代器、字符串的加法运算符、std::accumulate、boost库join)

在C++中,经常需要将多个字符串拼接成一个大字符串。这个过程很容易出错,但有一些技巧可以帮助我们轻松地实现这个目标。本文将介绍一些C++中join字符串的技巧。 一、使用stringstream stringstream是一个流。使用它可以将多个字符串连接起来,然后将它们转换为一个字符串。可以使用' ......

函数指针、std::function、std::bind

# 函数指针、std::function、std::bind ## 函数指针: - C++语法中可以直接将函数名作为指针, ```cpp void fun(int a, int b); ``` 在这个函数声明中,函数指针即为`fun`,传入要被调用的地方时只需要传入`fun`就可以。 但是这个函数指 ......
指针 函数 std function bind

c++ std::hash<std::string> 字符串哈希函数

## msvc 采用了[FNV-1a](http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param)的哈希算法 ``` // 众所周知 std::string 就是一个 basic_string template struct has ......
字符串 函数 std 字符 string

双通道MIL-STD-1553B总线通讯模块

* 双通道MIL-STD-1553B总线通讯模块 * 32bi,33 MHz CPCI/PCI/总线* 每个通道为A、B双冗余总线* 单功能可设置BC/RT/BM一种工作模式* 数据传输率: 4Mbps* 支持32位时标, 时标精度0.25微秒* 软件可设詈应答超时: 0-32767µs* 大容量的 ......
总线 模块 通道 MIL-STD 通讯

std::shared_ptr 线程安全方面的思考

一直惦记着 std::shared_ptr 线程安全的问题,看了些文章后,又怕过段时间忘记了,遂记录下来 std::shared_ptr 的线程安全问题主要有以下两种: 引用计数的加减操作是否线程安全 std::shared_ptr 修改指向时是否线程安全 第一个问题的答案: 是线程安全的,因为是原 ......
线程 shared_ptr 方面 shared std

配置 Forwarded Headers Middleware

来自微软的说明:[Configure ASP.NET Core to work with proxy servers and load balancers | Microsoft Learn](https://learn.microsoft.com/en-us/aspnet/core/host-an ......
Middleware Forwarded Headers

c++11 std::condition_variable

# std::condition_variable * 需要配合unique_lock使用,`wait(unique_lock&)` * notify_one()调用时,只有随机一个wait()线程会得到通知 * notify_all(),所有wait()线程会被通知并得到执行 * wait()调用 ......
condition_variable condition variable std 11

std::bitset 的常用函数

菜。 `flip`:反转。 `set()`:全部置 `1`。 `set(i)`:第 $i$ 位置 `1`。 `set(i, 0)`:第 $i$ 位置 `0`。 `reset`:置 `0`。 `count`:求 `1` 的个数。 `test`:返回第 $i$ 位是 `0/1`。 `any`:是否有 ` ......
函数 常用 bitset std

c++11 std::unique_lock

# std::unique_lock * 用法类似lock_guard,离开作用域后自动unlock * 定义的时候可以不需要mutex初始化,可以为空 * 可以手动调用lock(),unlock() ```cpp // unique_lock example #include // std::co ......
unique_lock unique lock std 11

让nlohmann json支持std::wstring和嵌套结构的序列化与反序列化

nlohmann json是一个star很高的C++ json解析库。 要让nlohmann json支持某个类型T,只要给这个类型T实现一个偏特化的struct adl_serializer<T>即可。adl_serializer是这个库里面针对泛型T预定义的适配器。 而嵌套结构,本身就支持的。使 ......
序列 nlohmann wstring 结构 json

X-Forwarded-For 客户端 IP 伪造过程及防范

单号: 【ID:1184794】【安全漏洞】【运营管理平台】【中危】存在IP地址伪造漏洞 问题: 漏洞名称:存在IP地址伪造漏洞 漏洞等级:中危 关联bug: 漏洞描述: 应用系统存在IP地址伪造漏洞,攻击者可通过修改HTTP请求包伪造IP地址绕过IP地址限制,访问或执行系统相关功能。 漏洞功能点: ......

std::move和std::forward

move和forward不进行任何操作,他们只负责类型转换。 move(x)等价于 static_cast<remove_reference_t<T>&&>(x)。因为T首先被剥夺引用,因此这里不会产生引用折叠,必定返回右值。 forward(x)等价于 static_cast<T&&> (x)。因 ......
std forward move

Overcoming Fear of Failure:Facing Your Fear of Moving Forward

It's almost impossible to go through life without experiencing some kind of failure. People who do so probably live so cautiously that they go nowhere ......
Fear Overcoming Failure Forward Facing

MIL-STD-1553B总线通信模块(1553B板卡)

MIL-STD-1553B总线通信模块(1553B板卡)产品具有以下特点: 1.产品覆盖多种接口CPCI/PXI/PCI/PC104/PC104+/USB等,满足用户不同平台的使用要求; 2.自主知识产权IP核,通信速率支持1M/4M ......
板卡 1553 总线 模块 MIL-STD

std::queue 中遇到释放内存错误的问题

项目上有个需求要用到 std::queue 顺序处理消息事件 简单的示例如下: struct MyEvent { MyEvent() { event_ = CreateEvent(nullptr, 0, 0, 0); } ~MyEvent() { std::cout << "MyEvent deco ......
内存 错误 问题 queue std

远程Linux显示WARNINGThe remote SSH server rejected X11 forwarding request解决

X11 forwarding依赖xorg-x11-xauth软件包,需要先安装xorg-x11-xauth软件包。1. 使用Xshell执行下面代码yum install xorg-x11-xauth -y 2. 重新连接测试,OK ......

c++ std::thread::joinable

# std::thread::joinable * 默认构造的thread对象 not joinable * join/detach之后 not joinable * 不能反复join/detach,会崩 * 当前线程会阻塞在join()调用处 * detach()不会阻塞当前线程,但是主进程结束后 ......
joinable thread std