unique_ptr unique std ptr

C++完美转发为什么必须要有std::forward?

先看一种情况,它的输出结果是什么? #include <iostream> using namespace std; void F(const int &a) { cout << "int: " << a << endl; } void F(int &&a) { cout << "int &&: " ......
forward std

const char *ptr和char const *ptr以及char* const ptr的区别

const char *ptr 和 char const *ptr => 这里这么理解,这个表示的是*ptr, 也就是指针指向的值,而修饰这个指针指向的值 (*ptr)的是const char或者char const, 表示两个意思: const => 表示是个常量,也就是说*ptr这个指针指向的值 ......
const char ptr

unique

unique unique 是 c++ 标准函数库之一 ,需要配合头文件 #include<algorithm>使用 作用:‘去掉’容器中相邻元素的重复元素 ,伪去除,相当于将重复元素添加到容器末尾 使用前提: 容器内元素必须有序 结果:返回最后一个不重复元素的地址下标 int a[N]; int ......
unique

CF1823D Unique Palindromes

题目链接 题解 知识点:构造。 首先反证法容易证明一个结论:每次增加一个字符,本质不同的回文子串至多增加一个。 那么无解的条件就是,\(c_i - c_{i-1} > x_i -x_{i-1}\) ,即距离不够数量的增加。 其他情况均有解,可以考虑利用 abc 作尾部填充,因为其只在一开始提供 \( ......
Palindromes Unique 1823D 1823 CF

std list多线程使用

#include <iostream> #include <list> #include <thread> #include <mutex> #include <condition_variable> #include <unistd.h> std::list<int> my_list; std:: ......
线程 list std

[转]Mysql中普通索引key 、主键索引(primary key) 、唯一索引(unique key)与index区别

原文地址:Mysql中普通索引key 、主键索引(primary key) 、唯一索引(unique key)与index区别 - 元小疯 - 博客园 一、索引的定义和由来: 索引被用来快速找出在一个列上用一特定值的行。没有索引,MySQL不得不首先以第一条记录开始并然后读完整个表直到它找出相关的行 ......
索引 key primary unique Mysql

取得std::ifstream对象的文件描述符

使用C++标准库无法取得std::ifstream对象的文件描述符,但GNU libstdc++库可以取得: ```cpp #include #include #include int main() { std::ifstream ifs("test.txt"); if (!ifs) { std:: ......
ifstream 对象 文件 std

std::copy与std::back_inserter引发的惨案

#include <iostream> #include <vector> #include <numeric> #include <sstream> int main() { std::vector v{1, 2, 3, 4, 5}; std::copy(begin(v), end(v), std ......
惨案 back_inserter std inserter copy

[C++] std::optional与RVO:最高效的std::optional实践与探究

## 返回值优化RVO 在cppreference中,是这么介绍RVO的 `In a return statement, when the operand is the name of a non-volatile object with automatic storage duration, wh ......
optional std RVO

【紧急科普】关于 std::vector 和 std::list 谁性能好的讲解

很多面试官。。。唉。不是一个年代的人吧。八股文当中现在倾向于说 list 中间插入性能更好。 1,std::vector 和 std::list 同属逻辑线性表。 2,std::vector 在内存当中连续,std::list 在内存当中不连续。 3,std::vector 因为在内存当中连续,随机 ......
科普 std 性能 vector list

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

java.lang.IllegalStateException: No primary or single unique constructor found for interface javax.servlet.http.HttpServletRequest问题的解决

# 问题描述 更改功能出现这样的问题; # 问题解决 经过不断试错,发现是这里出现问题: ![](https://img2023.cnblogs.com/blog/2808014/202308/2808014-20230831213643712-45226725.png) 然后将原来的这种: ![] ......

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

[LeetCode][96]unique-binary-search-trees

# Content Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 t ......

std::allocator

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

a build cache key that uniquely defines the task’s outputs based on its inputs

Build Cache https://docs.gradle.org/current/userguide/build_cache.html The Gradle build cache is a cache mechanism that aims to save time by reusing o ......
uniquely defines outputs inputs build

[LeetCode][62]unique-paths

# Content There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the ......
unique-paths LeetCode unique paths 62

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

C# 获取Windows系统设备唯一标识方法及代码(Unique Identifier)

唯一的标识一个设备是一个基本功能,可以拥有很多应用场景,比如软件授权(如何保证你的软件在授权后才能在特定机器上使用)、软件License,设备标识,设备身份识别等。 一、网卡MAC地址 MAC地址可能是最常用的标识方法,但是现在这种方法基本不可靠:一个电脑可能存在多个网卡,多个MAC地址,如典型的笔 ......
Identifier 标识 Windows 代码 方法

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

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

[ARC125D] Unique Subsequence

设 $pre_i$ 表示在 $i$ 之前最后一个和 $i$ 相同的数的位置,$dp_i$ 表示第 $i$ 个数为结尾的序列的合法方案数。 对于 $pre_i = 0$,即在 $i$ 之前不存在与 $i$ 相同的数,$dp_i$ 由 $\left[ 1,i - 1 \right]$ 转移过来。由于这个 ......
Subsequence Unique 125D ARC 125

关于 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