#include
#include
#include
#include
#include
#include
#include
#include
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
using std::for_each;
using std::shared_ptr;
using std::thread;
std::mutex g_mutex;
void my_thread1(int num, const string& str){
g_mutex.lock();
for(int i=0; i<10; i++){
cout << "num:" << num << ", name:" << str << endl;
}
g_mutex.unlock();
}
void my_thread2(){
int g_num = 20;
for (int i=0; i<10; i++){
cout << "num:" << g_num << endl;
}
}
int main(int argc,char * argv [ ]){
//类型推导
//auto自动根据初始化子的类型产生参数,首先应有被明确初始化的参数
vector myvec(3, 4);
for (auto itr = myvec.cbegin();itr != myvec.cend();itr++){
cout << *itr << endl;
}
int my_array[4] = {1,2,3,4};
for (auto &x : my_array){
x *= 2;
cout << x << endl;
}
//lambda函数,用[&]声明
vector someList(2, 5);
int total = 0;
int value = 10;
for_each(someList.begin(), someList.end(), [&, value](int x){
total += (x * value);
});
cout << total << endl;
//空指针nullptr
char *pc = nullptr;
char str[] = "hello world";
pc = str;
cout << pc << endl;
//通用智能指针
shared_ptr p_first(new double);
shared_ptr p_copy = p_first;
*p_copy = 21.1;
cout << *p_first << endl;
//c++11线程类std::thread,独占式互斥量std::mutex,允许超时的互斥量
int num = 1234;
string str_td = "qwer";
thread t(my_thread1,num,str_td);
thread t1(my_thread2);
t.join();
t1.join();
return 0;
}
相关推荐
C++11的新特性简单汇总介绍 (一)
什么是C++11 C++11是曾经被叫做C++0x,是对目前C++语言的扩展和修正,C++11不仅包含核心语言的新机能,而且扩展了C++的标准程序库(STL),并入了大部分的C++ Technical Report 1(TR1)程序库(数学的特殊函数除外)。 C++11包括大量的新特性:包括lambda表达式,类型推导关键字auto、decltype,和模板的大量改进。 1. 概述 最近在看C++ Primer5 刚好看到一半,总结一下C++11里面确实加了很多新东西,如果没有任何了解,别说自己写了,看别人写的代码估计都会有些吃力。C++ Primer5是学习C++11的比较好的书籍。这篇文章
轻量级C++11日志库spdlog
spdlog是一个只有头文件的轻量级C++11日志库,速度非常快,扩展性很强,更重要的是社区活跃,文档齐全。原来项目中使用的是log4cplus,感觉稍微有点笨重。它支持的平台包括Windows、Linux、Mac、Android。特点如下:1.一个字,快;三个字,非常快2.仅包括头文件3.日志格式丰富,格式化处理使用开源的fmt库(4.可选的异步模式这里的同步/异步指日志信息是否直接输出/写入文件,直接写就是同步,稍后写就是异步。
潜在图神经网络学习笔记(Latent Graph Neural Networks for Human Skeleton-based Action Recognition)
在本文中,我们从一个新的角度来解决这个问题,通过将非结构化的骨架数据映射到潜在空间,如图2所示,这里称为潜在特征空间或嵌入空间,其中一组项嵌入在一个流形中[ 1 ],并且在潜在空间中彼此更相似的项被放置在彼此更接近的位置。潜在空间中的位置可以被认为是由一组潜在变量定义的,这些潜在变量来源于对象的相似性。将骨架数据嵌入到流形中,消除了远近邻居之间的冗余依赖关系,以解决加权问题。得到具有多尺度聚合特征的稀疏图矩阵结构,以更好地理解骨骼关节的直接加权信息。
【C++11新特性】
本文摘要了C++11核心特性:1)类型推导(auto/decltype)简化变量声明;2)序列for循环遍历容器;3)lambda表达式用于创建匿名函数;4)构造函数(委托/继承)优化对象初始化;5)新型容器(array固定数组/forward_list单向链表);6)垃圾回收机制原理及替代方案;7)正则表达式基本语法。这些特性提升了代码简洁性和运行效率,其中lambda和容器改进对STL应用影响显著。
STM32F4驱动海康工业相机实战:从PWM信号到精准触发拍照(附完整代码)
本文详细介绍了如何使用STM32F4开发板驱动海康工业相机,实现PWM信号精准触发拍照的完整方案。从硬件连接到PWM信号生成,再到相机触发配置与延迟补偿,提供了实战经验和完整代码,帮助开发者解决工业相机硬件触发中的关键问题。
从DBC到ARXML:详解DaVinci Configurator中通信栈的自动化配置逻辑
本文深入解析了Vector公司DaVinci Configurator工具如何将DBC文件自动转换为符合AUTOSAR标准的ARXML配置,详细介绍了从DBC到ARXML的映射逻辑、自动化配置的边界与陷阱,以及工程实践中的优化策略。帮助工程师高效配置汽车电子系统中的通信协议,提升项目开发效率。
C++11新特性总结
C++11新特性总结
STM32F407控制舵机
STM32F407控制舵机运行 使用STM32F407控制舵机,首先来看下舵机图片 [黑红白,黑线接GND,红线接VCC,信号线接白色线(有的舵机线的颜色不同,例如褐色红色橘色,仅颜色不同接法还如上述)] 舵机需要信号的周期为20ms,即频率为50Hz。 接下来正式操作: 步骤一:STM32F4程序(本次程序的PWM信号产生的周期频率由定时器TIM14通道1产生(TIM14_CH1),想要使用其它定时器也没关系下面会讲到) #include "pwm.h" void TIM14_CH1_PWM_In
c++11新特性
在传统C头文件(stddef.h)中的定义如下。
STK相关总结
STK简介 一.SIM卡应用工具包(SIM Application Toolkit),又名CAT/USAT,它包含一系列终端与SIM卡的交互指令,SIM卡可以应用卡内的小应用程序和终端交互,从而实现增值服务的目的,STK包括三种类,STK-imsi切换,STK –OTA,STK-BIP 功能: (1) Profile download:配置下载,开机初始化SIM卡过程中,终端告诉SIM卡终端支持哪些功能,STK中download指终端将数据发送给SIM卡 (2) Proactive command: 主动式
量化交易python代码解析:从狙击手算法到最优限价算法
在金融市场的竞技场上,量化交易如同一位冷静的策略大师,它以数学模型为剑,以计算机程序为盾,精准出击,捕捉市场的微妙波动。本文将深入探讨五种核心量化交易算法:直接委托算法(DMA)、时间加权平均算法(TWAP)、冰山算法(Iceberg)、狙击手算法(Sniper)、条件委托算法(Stop)以及最优限价算法(BestLimit),揭开它们背后的运作机制与实战应用。
【C++】C++11新特性
对于 C++ 内置类型的数据,可以直接用 constexpr 修饰,但如果是自定义的数据类型(用 struct 或者 class 实现的),直接用 constexpr 修饰是不行的。注意:在R “xxx(raw string)xxx” 中,原始字符串必须用括号()括起来,括号的前后可以加其他字符串,所加的字符串会被忽略,并且()前后加的字符串必须相同。通过对基于范围的for循环语法的介绍可以得知,在for循环内部声明一个变量的引用就可以修改遍历的表达式中的元素的值,但是这并不适用于所有的情况,对应。
zynq的vitis工程烧录到Winbond(华邦)型号W25Q256JVEQ的QSPI FLAHS
vitis2023.1直接支持W25Q256JVEQ。
[C++系列] 89. C++11新特性简单介绍
文章目录1. C++11简介2. 列表初始化2.1 C++98中{}的初始化问题2.2 内置类型的列表初始化2.3 自定义类型的列表初始化3. 变量类型推导3.1 为什么需要类型推导3.2 decltype类型推导4. 基于范围的for循环5. final与override6. 智能指针7. 新增加容器8. 委派构造函数8.1 构造函数冗余造成重复8.2 委派构造函数9. 默认函数控制9.1 显...
Statistics and Machine Learning Toolbox
Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具
ET2012新版免狗免安装绿色软件
ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,
简单介绍C++ 11新增加的8种新特性
今天看了一本英文书,简单做了翻译对于c++新特性经常用但却不知道辨别,虽然c++17都已经出来了!一起学习吧!主要:初始化,auto、nullptr等//C++ 11 新特性#include "stdafx.h"#include <vector>#include<list>#include <set>#include <iostream>using ...
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
在DevC++中使用C++11
C++11有很多实用的新特性(详情见:C++11特性),那么如何在DevC++中使用这些新特性呢 1.点击Tools(工具)找到Compiler Options(编译选项) 2.在下图位置添加 “-std=c++11” (不含引号),并勾选红框中的选项 3.完成后如下图,点击OK即可 ...
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
为Sublime Text 3的C++编译器(g++)添加C++11标准的方法
-
DEV-C++设置C++11标准
DEV-C++默认的标准是C++98,改成C++11的方法如下: Tools -> Compiler Options -> Setting -> Code Generation -> Language standard(-std),选ISO C++11。
C++11介绍
国际标准化组织于2011年9月1号出版发布ISO/IEC 14882:2011,称为C++11。相比较C++98而言,C++11能更好地用于系统开发和库开发、语法更加泛华和简单化、更加稳定和安全,不仅功能更强大,而且能提升程序员的开发效率。 1.统一的初始化 什么叫做统一的初始化呢?例如:我们以前在往vector中插入数据的时候,只能一个元素一个元素调用push_back进行插入,现在我们可以...
让devcpp支持c++11
devcpp作为一款轻量级的c/c++编译器,虽然没有VS那般强大的功能,但是对于初学c++的同学来说,它不失为一款好的编译工具。c++11的新特性也备受码农们的热爱,为了让devcpp也能支持c++11需要做如下设置。 1.选择菜单栏的工具,打开编译选项。 2.在编译项中勾选“编译时加入以下命令”,并加入命令 -std=c++11。 3.然后点击确定即可。 ...
【工具用法】如何使Dev C++支持C++11特性
转载自点击打开链接1.先在dev的【工具】里找到【编译选项】2.一开始普遍的dev应该都是以下这个界面,在【编译时加入以下命令】栏是空白的且没有打钩。3.奇迹就在此刻改变.在这个【编译时加入以下命令】处打钩,然后在空白栏输入【-std=c++11】,确定.然后就能支持c++11-std=c++11,我试了一下C要小写c...
C++11特性
在2003年C++标准委员会曾经提交了一份技术勘误表(简称TC1),使得C++03这个名字已经取代了C++98称为C++11之前的最新C++标名称。不过由于C++03(TC1)主要是对C++98标准中的漏洞进行修复,语言的核心部分则没有改动,因此人们习惯性的把两个标准合并称为C++98/03标准。从C++0x到C++11,C++标准10年磨一剑,第二个真正意义上的标准珊珊来迟。
C++11系列-什么是C++11
C++11系列-什么是C++11 2013-08-01 什么是C++0x? C++0x是C++最新标准标准化过程中的曾用名,在这一系列文章中我们将介绍最新标准添加的一系列新的语言特性。在2011年9月份,C++0x正式由官方发布并命名C++11,现在很多编译器已经支持了部分C++11特性。 C++11包括大量的新特性:主要特征像lambda表达式和移动语义,实用的类型推
c++ 新特性概述、11、14、17,并简单举例
c++ 新特性概述、11、14、17,简单举例
5529



被折叠的 条评论
为什么被折叠?



