当前位置: 首页 > news >正文

C++11标准模板(STL)- 算法库 - 类似 std::accumulate,但不依序执行 -(std::reduce)

算法库

算法库提供大量用途的函数(例如查找、排序、计数、操作),它们在元素范围上操作。注意范围定义为 [first, last) ,其中 last 指代要查询或修改的最后元素的后一个元素。

类似 std::accumulate,但不依序执行

std::reduce
template<class InputIt>

typename std::iterator_traits<InputIt>::value_type reduce(

    InputIt first, InputIt last);
(1)(C++17 起)
template<class ExecutionPolicy, class ForwardIt>

typename std::iterator_traits<ForwardIt>::value_type reduce(
    ExecutionPolicy&& policy,

    ForwardIt first, ForwardIt last);
(2)(C++17 起)

template<class InputIt, class T>
T reduce(InputIt first, InputIt last, T init);

(3)(C++17 起)
template<class ExecutionPolicy, class ForwardIt, class T>

T reduce(ExecutionPolicy&& policy,

         ForwardIt first, ForwardIt last, T init);
(4)(C++17 起)

template<class InputIt, class T, class BinaryOp>
T reduce(InputIt first, InputIt last, T init, BinaryOp binary_op);

(5)(C++17 起)
template<class ExecutionPolicy, class ForwardIt, class T, class BinaryOp>

T reduce(ExecutionPolicy&& policy,

         ForwardIt first, ForwardIt last, T init, BinaryOp binary_op);
(6)(C++17 起)

1) 同 reduce(first, last, typename std::iterator_traits<InputIt>::value_type{})

3) 同 reduce(first, last, init, std::plus<>())

5) 在 binary_op 上以初值 init 规约范围 [first; last) ,可能以未指定方式排序聚合。

2,4,6) 同 (1,3,5) ,但按照 policy 执行。此重载仅若std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> 为 true才参与重载决议

binary_op 非结合或非交换,则行为非确定。

binary_op 修改 [first; last] 中任何元素或非法化范围中任何迭代器,含尾迭代器,则行为未定义。

参数

first, last-要应用算法的元素范围
init-广义和的初值
policy-使用的执行策略。细节见执行策略。
binary_op-将以未指定顺序应用于解引用输入迭代器结果、其他 binary_op 结果及 init 上的二元函数对象 (FunctionObject) 。
类型要求
- InputIt 必须满足遗留输入迭代器 (LegacyInputIterator) 的要求。
- ForwardIt 必须满足遗留向前迭代器 (LegacyForwardIterator) 的要求。
- T 必须满足可移动构造 (MoveConstructible) 的要求。而且 binary_op(init, *first)binary_op(*first, init)binary_op(init, init)binary_op(*first, *first) 必须可转换到 T

返回值

init*first*(first+1) 、…… *(last-1)binary_op 上的广义和,

其中广义和 GSUM(op, a
1, ..., a
N) 定义如下:

  • 若 N=1 ,则为 a
    1
  • 若 N > 1 ,则为 op(GSUM(op, b
    1, ..., b
    K), GSUM(op, b
    M, ..., b
    N)) ,其中
  • b
    1, ..., b
    N 可以是任何 a1, ..., aN 的排列,且
  • 1 < K+1 = M ≤ N

换言之, reduce 表现类似 std::accumulate ,除了范围中的元素可能以任意顺序分组并重排。

复杂度

O(last - first) 次应用 binary_op.

异常

拥有名为 ExecutionPolicy 的模板形参的重载按下列方式报告错误:

  • 若作为算法一部分调用的函数的执行抛出异常,且 ExecutionPolicy 为标准策略之一,则调用 std::terminate 。对于任何其他 ExecutionPolicy ,行为是实现定义的。
  • 若算法无法分配内存,则抛出 std::bad_alloc 。

注意

若为空,则返回不修改的 init

调用示例

#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>
#include <functional>
#include <time.h>
#include <random>
#include <vector>
#include <cassert>struct Cell
{int x;int y;Cell() = default;Cell(int a, int b): x(a), y(b) {}Cell &operator +=(const Cell &cell){x += cell.x;y += cell.y;return *this;}Cell &operator +(const Cell &cell){x += cell.x;y += cell.y;return *this;}Cell &operator *(const Cell &cell){x *= cell.x;y *= cell.y;return *this;}Cell &operator ++(){x += 1;y += 1;return *this;}bool operator <(const Cell &cell) const{if (x == cell.x){return y < cell.y;}else{return x < cell.x;}}bool operator >(const Cell &cell) const{if (x == cell.x){return y > cell.y;}else{return x > cell.x;}}bool operator ==(const Cell &cell) const{return x == cell.x && y == cell.y;}friend Cell operator+(const Cell &lcell, const Cell &rcell){Cell cell = lcell;cell.x += rcell.x;cell.y += rcell.y;return cell;}friend Cell operator-(const Cell &lcell, const Cell &rcell){Cell cell = lcell;cell.x -= rcell.x;cell.y -= rcell.y;return cell;}friend Cell operator*(const Cell &lcell, const Cell &rcell){Cell cell = lcell;cell.x *= rcell.x;cell.y *= rcell.y;return cell;}friend Cell operator/(const Cell &lcell, const Cell &rcell){Cell cell = lcell;cell.x /= rcell.x;cell.y /= rcell.y;return cell;}friend Cell operator%(const Cell &lcell, const Cell &rcell){Cell cell = lcell;cell.x %= rcell.x;cell.y %= rcell.y;return cell;}
};std::ostream &operator<<(std::ostream &os, const Cell &cell)
{os << "{" << cell.x << "," << cell.y << "}";return os;
}namespace std
{
template <typename InputIt, typename T, typename BinaryOperation>
T reduce(InputIt first, InputIt last, T init, BinaryOperation op)
{for (; first != last; ++first){init = op(std::move(init), *first);}return init;
}
}int main()
{std::cout << std::boolalpha;std::mt19937 g{std::random_device{}()};srand((unsigned)time(NULL));auto generate = [](){int n = std::rand() % 10 + 110;Cell cell{n, n};return cell;};//3) 构造拥有 count 个有值 value 的元素的容器。std::vector<Cell> vector1(8, generate());std::generate(vector1.begin(), vector1.end(), generate);std::sort(vector1.begin(), vector1.end());std::cout << "vector1:  ";std::copy(vector1.begin(), vector1.end(), std::ostream_iterator<Cell>(std::cout, " "));std::cout << std::endl;std::vector<Cell> vector2(vector1.size(), generate());std::generate(vector2.begin(), vector2.end(), generate);std::sort(vector2.begin(), vector2.end());std::cout << "vector2:  ";std::copy(vector2.begin(), vector2.end(), std::ostream_iterator<Cell>(std::cout, " "));std::cout << std::endl;for (size_t index = 0; index < vector1.size(); ++index){std::cout << "std::reduce(vector1.begin(), " << index << ", Cell{0, 0} std::plus<Cell>() ):    ";std::cout << std::reduce(vector1.begin(), vector1.begin() + index, Cell{0, 0}, std::plus<Cell>());std::cout << std::endl;}std::cout << std::endl;for (size_t index = 0; index < vector1.size(); ++index){std::cout << "std::reduce(vector1.begin(), " << index << ", Cell{0, 0} std::minus<Cell>() ):    ";std::cout << std::reduce(vector1.begin(), vector1.begin() + index, Cell{0, 0}, std::minus<Cell>());std::cout << std::endl;}std::cout << std::endl;for (size_t index = 0; index < vector2.size(); ++index){std::cout << "std::reduce(vector2.begin(), " << index << ", Cell{1, 1} std::multiplies<Cell>() ):    ";std::cout << std::reduce(vector2.begin(), vector2.begin() + index, Cell{1, 1}, std::multiplies<Cell>());std::cout << std::endl;}std::cout << std::endl;for (size_t index = 0; index < vector2.size(); ++index){std::cout << "std::reduce(vector2.begin(), " << index << ", Cell{1024, 1024} std::divides<Cell>() ):    ";std::cout << std::reduce(vector2.begin(), vector2.begin() + index, Cell{1024, 1024}, std::divides<Cell>());std::cout << std::endl;}std::cout << std::endl;for (size_t index = 0; index < vector2.size(); ++index){std::cout << "std::reduce(vector2.begin(), " << index << ", Cell{1024, 1024} std::modulus<Cell>() ):    ";std::cout << std::reduce(vector2.begin(), vector2.begin() + index, Cell{1024, 1024}, std::modulus<Cell>());std::cout << std::endl;}std::cout << std::endl;return 0;
}

输出

vector1:  {111,111} {112,112} {113,113} {115,115} {116,116} {116,116} {117,117} {119,119}
vector2:  {110,110} {112,112} {112,112} {114,114} {117,117} {117,117} {119,119} {119,119}
std::reduce(vector1.begin(), 0, Cell{0, 0} std::plus<Cell>() ):    {0,0}
std::reduce(vector1.begin(), 1, Cell{0, 0} std::plus<Cell>() ):    {111,111}
std::reduce(vector1.begin(), 2, Cell{0, 0} std::plus<Cell>() ):    {223,223}
std::reduce(vector1.begin(), 3, Cell{0, 0} std::plus<Cell>() ):    {336,336}
std::reduce(vector1.begin(), 4, Cell{0, 0} std::plus<Cell>() ):    {451,451}
std::reduce(vector1.begin(), 5, Cell{0, 0} std::plus<Cell>() ):    {567,567}
std::reduce(vector1.begin(), 6, Cell{0, 0} std::plus<Cell>() ):    {683,683}
std::reduce(vector1.begin(), 7, Cell{0, 0} std::plus<Cell>() ):    {800,800}std::reduce(vector1.begin(), 0, Cell{0, 0} std::minus<Cell>() ):    {0,0}
std::reduce(vector1.begin(), 1, Cell{0, 0} std::minus<Cell>() ):    {-111,-111}
std::reduce(vector1.begin(), 2, Cell{0, 0} std::minus<Cell>() ):    {-223,-223}
std::reduce(vector1.begin(), 3, Cell{0, 0} std::minus<Cell>() ):    {-336,-336}
std::reduce(vector1.begin(), 4, Cell{0, 0} std::minus<Cell>() ):    {-451,-451}
std::reduce(vector1.begin(), 5, Cell{0, 0} std::minus<Cell>() ):    {-567,-567}
std::reduce(vector1.begin(), 6, Cell{0, 0} std::minus<Cell>() ):    {-683,-683}
std::reduce(vector1.begin(), 7, Cell{0, 0} std::minus<Cell>() ):    {-800,-800}std::reduce(vector2.begin(), 0, Cell{1, 1} std::multiplies<Cell>() ):    {1,1}
std::reduce(vector2.begin(), 1, Cell{1, 1} std::multiplies<Cell>() ):    {110,110}
std::reduce(vector2.begin(), 2, Cell{1, 1} std::multiplies<Cell>() ):    {12320,12320}
std::reduce(vector2.begin(), 3, Cell{1, 1} std::multiplies<Cell>() ):    {1379840,1379840}
std::reduce(vector2.begin(), 4, Cell{1, 1} std::multiplies<Cell>() ):    {157301760,157301760}
std::reduce(vector2.begin(), 5, Cell{1, 1} std::multiplies<Cell>() ):    {1224436736,1224436736}
std::reduce(vector2.begin(), 6, Cell{1, 1} std::multiplies<Cell>() ):    {1525177344,1525177344}
std::reduce(vector2.begin(), 7, Cell{1, 1} std::multiplies<Cell>() ):    {1107477504,1107477504}std::reduce(vector2.begin(), 0, Cell{1024, 1024} std::divides<Cell>() ):    {1024,1024}
std::reduce(vector2.begin(), 1, Cell{1024, 1024} std::divides<Cell>() ):    {9,9}
std::reduce(vector2.begin(), 2, Cell{1024, 1024} std::divides<Cell>() ):    {0,0}
std::reduce(vector2.begin(), 3, Cell{1024, 1024} std::divides<Cell>() ):    {0,0}
std::reduce(vector2.begin(), 4, Cell{1024, 1024} std::divides<Cell>() ):    {0,0}
std::reduce(vector2.begin(), 5, Cell{1024, 1024} std::divides<Cell>() ):    {0,0}
std::reduce(vector2.begin(), 6, Cell{1024, 1024} std::divides<Cell>() ):    {0,0}
std::reduce(vector2.begin(), 7, Cell{1024, 1024} std::divides<Cell>() ):    {0,0}std::reduce(vector2.begin(), 0, Cell{1024, 1024} std::modulus<Cell>() ):    {1024,1024}
std::reduce(vector2.begin(), 1, Cell{1024, 1024} std::modulus<Cell>() ):    {34,34}
std::reduce(vector2.begin(), 2, Cell{1024, 1024} std::modulus<Cell>() ):    {34,34}
std::reduce(vector2.begin(), 3, Cell{1024, 1024} std::modulus<Cell>() ):    {34,34}
std::reduce(vector2.begin(), 4, Cell{1024, 1024} std::modulus<Cell>() ):    {34,34}
std::reduce(vector2.begin(), 5, Cell{1024, 1024} std::modulus<Cell>() ):    {34,34}
std::reduce(vector2.begin(), 6, Cell{1024, 1024} std::modulus<Cell>() ):    {34,34}
std::reduce(vector2.begin(), 7, Cell{1024, 1024} std::modulus<Cell>() ):    {34,34}

相关文章:

C++11标准模板(STL)- 算法库 - 类似 std::accumulate,但不依序执行 -(std::reduce)

算法库 算法库提供大量用途的函数&#xff08;例如查找、排序、计数、操作&#xff09;&#xff0c;它们在元素范围上操作。注意范围定义为 [first, last) &#xff0c;其中 last 指代要查询或修改的最后元素的后一个元素。 类似 std::accumulate&#xff0c;但不依序执行 std…...

反射机制的介绍

什么是反射 Java反射机制是Java语言一个很重要的特性&#xff0c;它使得Java具有了“动态性”。在Java程序运行时&#xff0c;对于任意的一个类&#xff0c;我们能不能知道这个类有哪些属性和方法呢&#xff1f;对于任意的一个对象&#xff0c;我们又能不能调用它任意的方法&a…...

AI图文带货,手把手教学,傻瓜操作,轻松日入500+,小白教程

通过自媒体的力量&#xff0c;帮助普通人成为企业家。 建立自己的财富事业&#xff0c;用你的影响力帮助更多的人。 从而实现你更加自由的生活方式。 记住关注我&#xff0c;不要错过每一次分享。 对标账号 作为公司的一个项目实际拆解者&#xff0c;最热门的项目怎么能不拆…...

java:实现简单的验证码功能

效果 实现思路 验证码图片的url由后端的一个Controller生成&#xff0c;前端请求这个Controller接口的时候根据当前时间生成一个uuid&#xff0c;并把这个uuid在前端使用localStorage缓存起来&#xff0c;下一次还是从缓存中获取。 Controller生成验证码之后&#xff0c;把前…...

MybatisPlus使用指南

MybatisPlus 1. 快速入门1.1 入门案例1.2 常见注解1.3 常见配置 2. 核心功能2.1 条件构造器2.2 自定义SQL2.3 Service接口 3. 扩展功能3.1 代码生成3.2 静态工具3.3 逻辑删除 4. 插件功能4.1 分页插件4.2 通用分页实体 1. 快速入门 1.1 入门案例 步骤一&#xff1a;引入Mybat…...

5. MongoDB 集合创建、更新、删除

1. 创建集合 1.1 语法 db.createCollection(name, options) 参数说明&#xff1a; name: 要创建的集合名称。options: 可选参数, 指定有关内存大小及索引的选项。 options 可以是如下参数&#xff1a; 参数名类型描述示例值capped布尔值是否创建一个固定大小的集合。truesize…...

PHP中如何将变量从函数传递给acf_add_filter

在PHP开发中&#xff0c;我们有时需要将变量从函数传递给acf的add_filter钩子。这样做可以让我们在acf字段加载时&#xff0c;对字段值进行动态修改。下面&#xff0c;我将详细介绍如何实现这一功能。 在acf中&#xff0c;我们使用add_filter来添加钩子&#xff0c;对字段的加…...

KNN算法的使用

目录 一、KNN 算法简介 二、KNN算法的使用 1.读取数据 2.处理数据 三、训练模型 1.导入KNN模块 2.训练模型 3.出厂前测试 四、进行测试 1.处理数据 2.进行测试 总结 一、KNN 算法简介 KNN 是一种基于实例的学习算法。它通过比较样本之间的距离来进行预测。算法的核心…...

java文件上传

导入jar包&#xff0c;或者maven <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> <dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>…...

MySQL 数据库经验总结

一、数据库操作 1. 创建数据库 CREATE DATABASE database_name;例如&#xff0c;创建一个名为 my_database 的数据库&#xff1a; CREATE DATABASE my_database;2. 选择数据库 USE database_name;要使用刚才创建的 my_database 数据库&#xff1a; USE my_database;3. 删除…...

Python环境安装及PIP安装(Mac OS版)

官网 https://www.python.org/downloads/ 安装python python-3.12.1-macos11.pkg下载后&#xff0c;安装一直下一步即可 验证是否安装成功&#xff0c;执行python3命令和pip3命令 配置环境变量 获取python3安装位置并配置在.bash_profile #查看python路径 which python3#…...

2024自动驾驶(多模态)大模型综述:从DriveGPT4、DriveMLM到DriveLM、DriveVLM

前言 由于今年以来&#xff0c;一直在不断深挖具身智能机器人相关&#xff0c;而自动驾驶其实和机器人有着无比密切的联系&#xff0c;甚至可以认为&#xff0c;汽车就是一个带着4个轮子的机器人 加之个人认为&#xff0c;目前大模型落地潜力最大的两个方向&#xff0c;一个是…...

晨控CK-GW08-EC与汇川AC801系列PLC的EtherCAT通讯连接说明手册

晨控CK-GW08-EC与汇川AC801系列PLC的EtherCAT通讯连接说明手册 晨控CK-GW08-EC是一款支持标准工业通讯协议EtherCAT的网关控制器,方便用户集成到PLC等控制系统中。系统还集成了8路读写接口&#xff0c;用户可通过通信接口使用EtherCAT协议对8路读写接口所连接的读卡器进行相对…...

向上or向下调整建堆 的时间复杂度的本质区别的讲解

知识点&#xff1a;&#xff08;N代表节点数&#xff0c;h代表高度&#xff09; 1&#xff1a;高度为h的满二叉树节点个数N为 2^&#xff08;h&#xff09;-1 即N 2^&#xff08;h&#xff09;-1 2&#xff1a;所以h log&#xff08;N1&#xff09; 一&#xff1a;向上…...

阿一网络安全实战演练之利用 REST URL 中的服务器端参数污染

所需知识 要解决这个实验室问题&#xff0c;您需要了解以下内容&#xff1a; 如何确定用户输入是否包含在服务器端的 URL 路径或查询字符串中。如何使用路径遍历序列尝试更改服务器端请求。如何查找 API 文档。 这些内容在我们的 API 测试学院主题中有涵盖。 进入实验室 研…...

[游戏开发] LuaTable转string存读二进制文件

UE5和Unity通用此方案&#xff0c;只不过读写文件的接口略有不同&#xff0c;lua代码的处理是相同的。 下面两个方法是 LuaTable和字符串互相转换的代码 function XUtils.luaTableToString(tab, sp)sp sp or ""local s ""for k,v in pairs(tab) doif t…...

光伏业务管理系统的一些妙用功能

现在信息化流程化基本上每个行业都必须要有的了&#xff0c;光伏业务管理系统软件是一种专门用于光伏产业运营和管理的综合性系统&#xff0c;它结合了信息技术、数据分析、项目管理、客户管理等多个领域的知识&#xff0c;为光伏企业提供了一个全面、高效、智能的管理平台&…...

Java面试八股之请简述消息队列的发布订阅模式

请简述消息队列的发布订阅模式 发布订阅&#xff08;Publish-Subscribe&#xff0c;简称 Pub/Sub&#xff09;模型是一种消息传递模式&#xff0c;它在组件之间提供了高度的解耦和灵活性。这种模式广泛应用于分布式系统、事件驱动架构以及消息队列系统中。下面是发布订阅模型的…...

七、2 ADC数模转换器有关函数介绍(Keil5)

函数介绍 &#xff08;1&#xff09;ADCCLK的配置函数&#xff08;在rcc.h中&#xff09; &#xff08;2&#xff09;ADC的库函数&#xff08;在adc.h中&#xff09;...

了解载波侦听多路访问CSMA(上)

1.CSMA的思想 CSMA的全称是Carrier Sense Multiple Access&#xff0c;在笔者的理解中&#xff0c;其更趋向于一种理论研究的随机接入协议&#xff0c;或者说&#xff0c;基于其思想诞生了比如CSMA/CD与CSMA/CA这样的具体协议。CSMA可以分成以下三种&#xff1a; 1-persistent…...

黑马Mybatis

Mybatis 表现层&#xff1a;页面展示 业务层&#xff1a;逻辑处理 持久层&#xff1a;持久数据化保存 在这里插入图片描述 Mybatis快速入门 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6501c2109c4442118ceb6014725e48e4.png //logback.xml <?xml ver…...

【位运算】消失的两个数字(hard)

消失的两个数字&#xff08;hard&#xff09; 题⽬描述&#xff1a;解法&#xff08;位运算&#xff09;&#xff1a;Java 算法代码&#xff1a;更简便代码 题⽬链接&#xff1a;⾯试题 17.19. 消失的两个数字 题⽬描述&#xff1a; 给定⼀个数组&#xff0c;包含从 1 到 N 所有…...

定时器任务——若依源码分析

分析util包下面的工具类schedule utils&#xff1a; ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类&#xff0c;封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz&#xff0c;先构建任务的 JobD…...

[ICLR 2022]How Much Can CLIP Benefit Vision-and-Language Tasks?

论文网址&#xff1a;pdf 英文是纯手打的&#xff01;论文原文的summarizing and paraphrasing。可能会出现难以避免的拼写错误和语法错误&#xff0c;若有发现欢迎评论指正&#xff01;文章偏向于笔记&#xff0c;谨慎食用 目录 1. 心得 2. 论文逐段精读 2.1. Abstract 2…...

Unity | AmplifyShaderEditor插件基础(第七集:平面波动shader)

目录 一、&#x1f44b;&#x1f3fb;前言 二、&#x1f608;sinx波动的基本原理 三、&#x1f608;波动起来 1.sinx节点介绍 2.vertexPosition 3.集成Vector3 a.节点Append b.连起来 4.波动起来 a.波动的原理 b.时间节点 c.sinx的处理 四、&#x1f30a;波动优化…...

技术栈RabbitMq的介绍和使用

目录 1. 什么是消息队列&#xff1f;2. 消息队列的优点3. RabbitMQ 消息队列概述4. RabbitMQ 安装5. Exchange 四种类型5.1 direct 精准匹配5.2 fanout 广播5.3 topic 正则匹配 6. RabbitMQ 队列模式6.1 简单队列模式6.2 工作队列模式6.3 发布/订阅模式6.4 路由模式6.5 主题模式…...

招商蛇口 | 执笔CID,启幕低密生活新境

作为中国城市生长的力量&#xff0c;招商蛇口以“美好生活承载者”为使命&#xff0c;深耕全球111座城市&#xff0c;以央企担当匠造时代理想人居。从深圳湾的开拓基因到西安高新CID的战略落子&#xff0c;招商蛇口始终与城市发展同频共振&#xff0c;以建筑诠释对土地与生活的…...

纯 Java 项目(非 SpringBoot)集成 Mybatis-Plus 和 Mybatis-Plus-Join

纯 Java 项目&#xff08;非 SpringBoot&#xff09;集成 Mybatis-Plus 和 Mybatis-Plus-Join 1、依赖1.1、依赖版本1.2、pom.xml 2、代码2.1、SqlSession 构造器2.2、MybatisPlus代码生成器2.3、获取 config.yml 配置2.3.1、config.yml2.3.2、项目配置类 2.4、ftl 模板2.4.1、…...

scikit-learn机器学习

# 同时添加如下代码, 这样每次环境(kernel)启动的时候只要运行下方代码即可: # Also add the following code, # so that every time the environment (kernel) starts, # just run the following code: import sys sys.path.append(/home/aistudio/external-libraries)机…...

STM32HAL库USART源代码解析及应用

STM32HAL库USART源代码解析 前言STM32CubeIDE配置串口USART和UART的选择使用模式参数设置GPIO配置DMA配置中断配置硬件流控制使能生成代码解析和使用方法串口初始化__UART_HandleTypeDef结构体浅析HAL库代码实际使用方法使用轮询方式发送使用轮询方式接收使用中断方式发送使用中…...