尾置返回值类型decltype

C++(11):动态声明函数的返回值类型 通过结合auto和decltype,可以动态的声明函数的返回值类型: #include <iostream> using namespace std; template<class T1, class T2> auto add(T1 t1, T2 t2) -> decltype(t1 + t2) //通过auto和decltype动态的声明函数的返回值类型 { return t1 + t2; } int main(){ auto a = add(5, 1.66 阅读详情
#include <iostream>
#include <type_traits> // std::decay


// 若返回值类型与参数类型有关,可以让编译器自动推导
template<typename T1, typename T2>
auto max(T1 t1, T2 t2) {
    return t1<t2?t2:t1;
}

// 等价上面,使用decay对类型进行弱化,去掉const、引用等
template<typename T1, typename T2>
auto max1(T1 t1, T2 t2)->typename std::decay<decltype(true?t2:t1)>::type {
    return t1<t2?t2:t1;
}

// 若T是引用时,使用尾置返回值类型可能被推导为引用类型
template<typename T1, typename T2>
auto max2(T1 t1, T2 t2)->decltype(true?t2:t1) {
    return t1<t2?t2:t1;
}



// common_type<>和decay也是返回值类型退化的
template<typename T1, typename T2>
std::common_type<T1, T2> max3(T1 t1, T2 t2) {
    return t1<t2?t2:t1;
}

void Test(){
    std::cout<<std::boolalpha<<std::is_same_v<decltype(max(4, 7.2)), double><<std::endl; // true
    std::cout<<std::boolalpha<<std::is_same_v<decltype(max(7.2, 4)), double><<std::endl; // true

    double a = 7.2;
    double &b = a;
    int c = 4;

    std::cout<<std::boolalpha<<std::is_reference_v<double&><<std::endl; //true
    std::cout<<std::boolalpha<<std::is_same_v<decltype(max2(b,c)), double><<std::endl; // true, 推导应该为double&才对啊
    std::cout<<std::boolalpha<<std::is_reference_v<decltype(max2(b,c))><<std::endl; // false, 为啥测试结果是double而不是double&

}


int main()
{
     Test();
}


c++通过自然语言处理技术分析语音信号音高 其中,缓冲区大小为2048,最小基频为80Hz,最大基频为1000Hz。通常情况下,音高在85Hz到255Hz之间,因此可以根据实际情况修改最小和最大基频值。C++中可以使用数字信号处理库或语音处理库,比如MATLAB、Praat、YIN算法等等来进行音高分析。对于语音信号的音高分析,可以使用基频提取技术。基频是指一个声音周期的重复率,也就是一个声音波形中最长的周期。通常情况下,人的声音基频范围是85Hz到255Hz。这段代码使用了YIN算法来计算语音信号的基频,得出的结果即为音高。 阅读详情

相关推荐

Claude Skills 深度讲解

阶段 1:Function Call(2023)├─ 大模型可以调用外部工具├─ 问题:缺乏对任务的深度理解└─ 局限:工具调用简单线性阶段 2:MCP 上下文工程(2024)├─ 大模型有了更丰富的上下文和工具├─ 问题:仍然需要手动编写复杂的 Prompt└─ 局限:每次对话都需要重新加载上下文阶段 3:Claude Skills(2025)├─ 大模型有了「能力模块」的概念├─ 可以动态加载、组合、执行专门的工作流├─ 真正实现了「知识的模块化和复用」

u013134676的博客 1464

置尾返回类型 decltype auto

/* auto : 由编译器推断类型 decltype (表达式) -&gt; 推断出类型 , 比如: decltype(1+2) -&gt; int; decltype 需要注意 :表达式能明确类型才能推断出来, 如果是模板参数则无法推断,因为 模板类型参数总是在实例化后才能确定. ...

x 367

【已解决】App unavailable Unfortunately, Claude is only available in certain countries and regions

App unavailable Unfortunately, Claude is only available in certain countries and regions right now. We will soon publish a list of supported locations on our website.

weixin_43941438的博客 3万+

Effective C++: std::decay和decltype

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34023863的博客 764

QCM2290 PM-3 如何让mirco-usb支持关机充电

PM4125-3插入type-C触发开机进入关机充电的CC脚中断条件是否可以软件上屏蔽, 做到只通过VBUS中断即可触发进入关机充电模式,达到和PM4125-2的效果一样只要插入micro USB 就可以触发进入关机充电模式。硬件团队提议修改寄存器 SCHG_L_MISC_SYSOK_CFG 0x164A bit[4] 目前修改如下 — a/BOOT.XF.4.1/boot_images/QcomPkg/Library/PmicLib/target/Agatti_pmCocos/psi/pm_confi

墨染天玑的博客 443

工业-实时数据采集

在主节点使用Flume采集/data_log目录下实时日志文件中的数据,将数据存入到Kafka的Topic 中(Topic名称分别为ChangeRecord、ProduceRecord和EnvironmentData,分区数为4),Flume 采集ChangeRecord。

dafsq的博客 590

decltype

decltype 类似于sizeof操作符,decltype也不需对其操作数求值。粗略来说,decltype(e)返回类型前,进行了如下推导: 1.若表达式e指向一个局部变量、命名空间作用域变量、静态成员变量或函数参数,那么返回类型即为该变量(或参数)的“声明类型”; 2.若e是一个左值(lvalue,即“可寻址值”),则decltype(e)将返回T&,其中T为e的类型;

coutamg的博客 3387

股票价格预测的秘密武器:用C#实现蒙特卡洛路径模拟,轻松掌握市场波动规律!

摘要: 蒙特卡洛模拟是股票预测的有效工具,通过随机抽样模拟价格路径,克服传统技术分析的局限性。其核心模型是几何布朗运动(GBM),描述股价随机变化过程。C#实现的关键步骤包括:1)获取输入参数;2)生成随机数路径;3)分析结果。该方法不预测具体价格,而是提供可能的价格范围,帮助投资者评估风险。代码结构清晰,分为输入、模拟、分析和可视化四个模块,通过参数封装提高可读性,适用于不确定市场的概率预测。

墨夶的博客 601

【C++新特性】 - 尾置返回类型

常规函数声明中,函数返回值类型都是在首位,例如: int GetType(); C++11开始引入了尾置返回类型,将函数返回值类型放置在函数尾部(如果函数声明与实现写在一起,则放置在函数体之前),使用->符号隔开,并将首位的返回值使用auto关键字替代,例如: auto GetType() -> int; auto GetAge() -> int { return 18; } 任何函数的定义都能使用尾置返回类型,但是这种类型一般用于返回类型比较复杂的函数用于简化函数定义(比如数组

BruceZong的专栏 2299

SCADA|RESTful学习,Apipost通过GET获取KingSCADA实时数据

本文介绍了如何使用RESTful实现SCADA与MES系统对接。主要包括:1)对比RESTful与其他协议的性能指标;2)KingSCADA作为Server/Client的三种应用场景;3)详细演示KingSCADA3.8作为Server端的配置过程,包括端口设置和API测试。通过Apipost工具测试获取变量值及数据回写接口,其中数据回写需使用MD5加密密码。文章最后指出回写测试失败的情况,但未分析具体原因。全文以实际工程应用为导向,提供了具体操作步骤和技术细节。

做有价值的事,积累有价值的笔记! 625

使用pyqt5实现可勾选的测试用例界面

使用pyqt5实现可勾选的测试用例界面

天赐好车的博客 629

【C++中的decltype是什么】

特性 auto decltype推导阶段 编译时 编译时推导规则 忽略顶层 const 和引用 保留完整类型信息使用场景 变量类型推导 表达式类型推导返回值推导 C++14 支持直接推导 C++11 中用于尾置返回类型引用和 const 默认忽略,除非显式指定 保留auto 更适合简化代码和变量类型推导。decltype 更适合需要精确控制类型的场景,如模板编程和复杂表达式类型推导。

qq_42524389的博客 626

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

C++之函数的返回值:返回值是引用类型、返回值是指针类型、返回值是初始化列表、返回值由关键字decltype推断、尾置返回值类型

C++之函数的返回值:返回值是引用类型、返回值是指针类型、返回值是初始化列表、返回值由关键字decltype推断、尾置返回值类型

qq_42279379的博客 422

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

c++函数-返回值类型(返回数组指针,尾置返回类型)

c++ 函数返回值类型,decltype 关键字

weixin_64612849的博客 1608

深度学习工具包 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');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【C++】超详细入门——详解函数返回类型

详解C++中函数的返回类型

ikun的博仔的博客 6527

c++ 函数的返回值

函数返回值 不要返回局部对象的引用或者指针 引用返回左值,其他返回类型得到右值 main函数返回值中,0表示成功,其他表示识别。 列表初始化返回值 c++ 11新标准规定, 函数可以返回花括号包围的值列表。其实,就是使用列表初始化的方式对表示函数返回的临时变量进行初始化。 vector&lt;string&gt; process() { return {"funca",...

William 7983

第六章:返回值类型和return语句

一、什么情况下返回的引用无效?什么情况下反回常量的引用无效? 知识点1:返回的引用无效:局部临时变量或者局部对象的引用对于返回都是无效的,因为在函数终止之后,局部变量或者对象的引用不再指向有效的内存区域。若是常量在函数调用之前存在,引用即可用。 知识点2:可以对返回值是非常量引用的函数结果赋值。 **来!举个例子来理解一下啊!!!** #include <iostream> ...

WangY.H 1233

6.3 返回类型和return语句

无

Micoreal的博客 1308

C++笔记 6.2 函数返回类型

primer C++笔记 返回类型和return语句 无返回值函数 有返回值函数 返回类类型的函数和调用运算符 ()调用运算符 列表初始化返回值 主函数main的返回值 递归 返回数组指针 声明一个返回数组指针的函数 使用尾置返回类型 使用decltype ...

qq_36333986的博客 304

第六章_函数_6.3 返回类型和 return 语句

6.3 返回类型和 return 语句 return 语句终止当前正在执行的函数并将控制权返回到调用该函数的地方。 6.3.1 无返回值函数 没有返回值的 return 语句只能用在返回类型是 void 的函数中。 通常情况下,void 函数如果想在它的中间位置提前退出,可以使用 return 语句,类似 break。 6.3.2 有返回值函数 只要函数的类型不是 void,则该函数内的每条 return 语句必须返回一个值。return 语句返回值的类型必须与函数的返回类型相同,或者能隐式转换成函数的返回

jkhcx1990的博客 740

返回类型和 return 语句

return 语句终止当前正在执行的函数并将控制权返回到调用该函数的地方。return 语句有两种形式: return; return expression; 不要返回局部对象的引用或指针: 函数完成后,它所占用的存储空间也随之被释放掉。因此函数终止意味着局部变量的引用和指针将指向不再有效的内存区域: 一种典型的错误就是将一个指向局部变量的指针作为函数的返回值。由于该数组是局部变量,因...

weixin_30905981的博客 438

【C++基础】第三十六课:返回类型和return语句

return语句终止当前正在执行的函数并将控制权返回到调用该函数的地方。return;

qq_34222839的博客 1120

【共读Primer】52.[6.3]返回类型和return语句--返回数组指针 Page205

数组不能被拷贝,所以返回值不能是数组类型。 但是我们可以使用返回指针的方式来实现返回数组的目的 声明一个返回数组指针的函数 int (*fun(int i))[10]; // func(int i) 表示调用func函数时需要一个int类型的实参 // (*func(int i)) 意味着我们可以对函数调用的结果执行解引用操作 // (*func(int i))[10] 表示解引用...

weixin_30888027的博客 62

返回类型和return语句

return语句终止当前正在执行的函数并将控制权返回到调用该函数的地方。return语句有两种形式: return; return expression;   无返回值函数 没有返回值的return语句只能用在返回类型是void的函数中。返回void的函数不要求非得有return语句,因为在这类函数的最后一句后面会隐含地执行return。 通常情况下,void函数如果想在它的中间位置提...

weixin_34384915的博客 376

<C++学习十九>返回类型和return语句

摘要: 本篇博客仅作为笔记,如有侵权,请联系,立即删除(网上找博客学习,然后手记笔记,因纸质笔记不便保存,所以保存到网络笔记)。   return语句终止当前正在执行的函数并将控制权返回到调用该函数的地方。return语句有两种形式:   return;   return expression;   1、无返回值函数   没有返回值的return语句只能在返回类型是void的函数中。返回...

weixin_30328063的博客 498

c++ 拆分函数返回值和参数类型

在c++中,函数参数类型和返回值类型通常是一个比较明确的信息,好像确实无需在这个上面费周折。然而,硬编码数据类型会让代码复用性下降,如果能够通过某种方式自动获取函数参数和返回值类型,对于代码的可复用性,可读性和整洁性都有较大的提升。上面的代码,gmock在使用的时候是配合宏实现不同类型函数的统一。

yuanshenqiang的博客 380
上一篇: C++ 去掉const
下一篇: 变参模板函数
最后冰吻free
博客等级 码龄12年 121粉丝 371原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值