双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

Rob Murray分析的Obfuscated C++, 不懂STL的人可能看不懂。

myan myan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Obfuscated C++

Rob Murray

. Last Month's Obfuscated C++

Last month we asked you to explain the output of the following program:
#include
#include
using namespace std;

template
void g(int size, op o, const char* sep = "") {
for(int i = 0; i < size; ++i)
cout << o(i) << sep;
}

template
struct w {
char* operator()(int a) {
return g(size,binder1st(op(),a),"\t"),"\n";
}
};

template
void
x(){
g(size, w());
}

int main(){
x,6>();
return 0;
}

This constructor of the x template prints a multiplication table of six rows and six columns, for example:
0 0 0 0 0 0
0 1 2 3 4 5
0 2 4 6 8 10
0 3 6 9 12 15
0 4 8 12 16 20
0 5 10 15 20 25

To understand how this works, we'll first examine the template function g(size,op,sep). op is a function object. The function object is "called" with the first size integers (starting at 0) and the results printed (separated by the string specified by the optional sep argument). We use this function twice.

The first call is in the template function x. It calls g, passing size and an object of type w<op,size>. For our example, this will call g(6,w<multiplies<int>,6>,""), which will cause the following invocations to occur:
w<'multiplies<int>,6>::operator()(0); //rownum = 0
w<multiplies<int>,6>::operator()(1); //rownum = 1
...
w<multiplies<int>,6>::operator()(5); //rownum = 5

Each of these constructors prints a single row of the table. It does this by creating a new function object
binder1st<multiplies<int> >(multiplies(),rownum)

where rownum is the row being printed. This binder1st object is passed to g(), which invokes operator() on the object for each of the integers from 0 to size-1. This prints a single row of the table, using a tab as the separator argument.

binder1st is a standard template class defined in the <functional> header. It takes a binary function object (in this case, multiplies<int>) and a single operand, and creates a new unary function object that "binds" the operand as the first operand of the binary function. This resulting object is invoked by calling operator(), passing a single operand. operator() returns the result of applying the original binary function to the "bound" operand and the operand supplied at the call.

In our example, the row index is "bound" as the first operand. For each column, the invocation of the binder1st object invokes multiplies<int>(int,int), passing the row and column indices respectively; the result is printed by g.

For bonus credit: Explain how the newline at the end of each row is printed.

Parameterizing the operation as a function object allows us to generate tables for other operations. For instance, x<plus<int>,4>() gives us:
0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6




This Month's Obfuscated C++

This month's Obfuscated C++ tests your knowledge of some of the standard template libraries. What is the output of the following program?
#include <iostream>
#include <list>
#include <iterator>
#include <algorithm>

struct {
void operator()(int i){cout<<i<<"\n";}
} c;
int main(){
list<int> il(2,1);
list<int>::iterator i1(il.begin()),i2(i1);i2++;
back_insert_iterator<list<int> >i3(il);
for(;*i1<20000;i1++,++i2)
*i3=*i1+*i2;
for_each(il.begin(),il.end(),c);
return 0;
}


...全文

相关推荐

具有PWM控制VSC-HVDC链路的IEEE30总线传输系统(Simulink仿真实现)

内容概要:本文构建了一个包含PWM控制VSC-HVDC链路的IEEE30节点电力传输系统,并基于Simulink平台完成了系统的建模仿真。该模型聚焦于高压直流输电(HVDC)技术在区域电网互联中的应用,采用电压源型换流器(VSC)与脉宽调制(PWM)技术实现高效、灵活的电能传输。研究重点在于分析VSC-HVDC链路在复杂多节点电网中对潮流分布、系统稳定性及电能质量的调控能力,特别关注其在区域电网互联、新能源大规模接入以及跨区域电力交换等场景下的动态响应特性与控制性能,为现代智能电网的发展提供技术支撑与仿真验证手段。; 适合人群:具备电力系统、电气工程或自动化等相关专业背景的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于研究VSC-HVDC在多节点电网(如IEEE30节点)中的建模与仿真方法;②分析PWM控制策略下HVDC链路对电网潮流分布、电压稳定性和故障穿越能力的影响;③为区域电网互联、新能源并网及智能电网调度等课题提供仿真基础和技术验证。; 阅读建议:此资源以Simulink仿真实现为核心,建议读者在掌握电力电子技术和电力系统分析基础知识的前提下,结合仿真模型深入理解VSC-HVDC的工作原理与控制策略。在学习过程中,应着重关注模型参数设置、控制环路设计及仿真结果的分析,以达到理论与实践相结合的目的。

woshilaiwade

基于KDE-CDF置信带的不确定综合能源系统鲁棒调度优化研究(Matlab代码实现)

内容概要:本研究针对不确定综合能源系统中的鲁棒调度优化问题,提出一种基于核密度估计-累积分布函数(KDE-CDF)置信带的建模方法,用以精确刻画风能、光伏及负荷等不确定性因素的非正态概率分布特征。通过构建KDE-CDF模型,能够有效捕捉实际运行中新能源出力与负荷需求的波动性与随机性,并在此基础上设计鲁棒优化调度框架,提升系统在不确定性环境下的运行可靠性与经济性。该方法结合Matlab编程实现,综合考虑系统运行成本、峰谷差、碳排放等多重目标,实现多维度协调优化。研究还探讨了与智能优化算法(如粒子群算法)相结合的应用路径,增强了模型的求解效率与工程实用性,为含多种储能装置、电转气设备及碳捕集系统的复杂综合能源系统提供了科学的调度决策支持。; 适合人群:具备电力系统分析、优化理论基础及Matlab编程能力的研究生、科研人员,以及从事综合能源系统规划、运行与调度工作的工程技术人员。; 使用场景及目标:①解决高比例可再生能源接入背景下综合能源系统调度中的不确定性建模难题;②提升调度方案在面对新能源强波动性时的鲁棒性与适应能力;③为融合多类型灵活性资源(如储能、电转气、碳捕集)的综合能源系统提供精细化、可落地的优化运行策略。; 阅读建议:建议读者在掌握概率统计、随机优化与电力系统运行基础知识的前提下,结合文中提供的Matlab代码进行实践操作,重点关注KDE-CDF置信带的构建流程及其在鲁棒优化模型中的嵌入机制,通过调整输入数据分布、参数设置与场景配置开展仿真对比实验,深入理解不确定性建模精度对调度决策质量的影响,进而掌握从数据驱动角度提升系统鲁棒性的关键技术路径。

抬头望远方

chrome-headless-shell-mac-x64-160.0.8160.0(Canary).zip

内容概要:Chrome for Testing 官方 chrome-headless-shell 160.0.8160.0 x64 平台(金丝雀版通道),原版未修改,附来源说明。 适合人群:x64 上的自动化测试工程师、爬虫开发者、CI 环境搭建者。 使用场景及目标:①无头浏览器(Playwright/Puppeteer/Selenium 无界面自动化与爬虫的运行内核);②服务器/容器离线内置;③版本精准匹配(chromedriver 与 Chrome 需同大版本)。 其他说明:Chrome for Testing 为 Google 官方发布、允许自由分发的文件;本资源为第三方整理的下载便利服务。

LCG元

多智能体-系统-形成-控制 附matlab代码.rar

多智能体-系统-形成-控制 附matlab代码.rar

天天Matlab科研工作室

含分布式电源的配电网可靠性评估研究(Matlab代码实现)

内容概要:本文系统研究了含分布式电源的配电网可靠性评估方法,基于Matlab代码实现了完整的评估模型与算法框架。研究深入分析了分布式电源接入后对配电网结构与运行特性的影响,重点探讨了其对供电可靠性的作用机制。采用序贯蒙特卡洛模拟法对系统各类状态进行抽样与仿真,综合考虑了分布式电源出力的随机性、负荷波动性以及网络拓扑变化等多种不确定性因素,精确计算了系统及负荷点的多项可靠性指标。通过在标准测试系统上的仿真实验,验证了所提方法的有效性和实用性,为新型电力系统环境下配电网的规划、运行与可靠性提升提供了有力的技术支撑和决策依据。; 适合人群:具备电力系统分析、概率统计及可靠性基础理论知识,熟悉Matlab编程语言,从事电力系统规划、运行、可靠性评估等相关工作的科研人员、高校研究生以及电力行业工程师。; 使用场景及目标:①掌握含分布式电源的现代配电网可靠性评估的核心理论与关键技术;②学习并实践基于序贯蒙特卡洛模拟的电力系统可靠性分析算法的Matlab实现方法;③为实际工程中分布式电源的优化配置、配电网的升级改造以及制定可靠性提升策略提供科学的仿真工具和量化分析依据。; 阅读建议:建议读者结合文中提供的Matlab代码,逐行阅读并运行程序,重点理解系统建模、状态抽样、潮流计算与指标统计等核心模块的实现逻辑。可尝试调整分布式电源的类型、容量、接入位置及负荷水平等参数,观察其对系统可靠性指标的影响趋势,从而深化对系统动态行为与关键影响因素的理解。

@橘柑橙柠桔柚
评论 5
收藏 已收藏
分享
返回顶部
myan
非技术区 15,446 成员 58,111 内容