Rob Murray分析的Obfuscated C++, 不懂STL的人可能看不懂。
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;
}
相关推荐
jvm指令使用说明.html
jvm指令使用说明.html
基于一阶谐波相位法的星载SAR多普勒中心频率估计与距离向拟合研究(Matlab代码实现)
内容概要:本文围绕基于一阶谐波相位法的星载合成孔径雷达(SAR)多普勒中心频率估计与距离向拟合方法展开研究,提出了一种结合一阶谐波相位模型的参数估计方法,用于精确估计SAR信号的多普勒中心频率,并在此基础上实现距离向信号的高精度拟合。该方法利用回波信号的相位特性,通过提取一阶谐波分量进行建模分析,有效提升了多普勒参数估计的精度与稳定性,尤其适用于高速运动平台下的星载SAR系统。研究通过Matlab编程实现了完整的算法流程,包括信号建模、相位提取、谐波分析、参数优化与拟合验证,展示了良好的仿真效果与工程应用潜力。; 适合人群:具备雷达信号处理基础知识,熟悉Matlab编程,从事遥感、SAR成像、航天电子等相关领域研究的研发人员及研究生;工作年限1-5年内的工程技术人才。; 使用场景及目标:①用于星载SAR系统中多普勒参数的高精度估计,提升成像质量;②作为SAR信号处理算法模块集成于地面处理系统或星上实时处理单元;③为相关科研项目、论文复现或工程开发提供可运行的Matlab代码参考与技术验证平台。; 阅读建议:建议读者结合SAR信号模型基础理论,逐步调试代码中的各处理环节,重点关注相位提取与谐波拟合部分的实现逻辑,并可通过改变信噪比、运动参数等条件进行敏感性分析,深入理解算法性能边界与优化方向。
Maven Kafka Java开发环境jar包
源码直接下载地址: https://pan.quark.cn/s/1670ca3cbea6 在Java编程领域,Apache Kafka被视为一种普遍应用的分布式流处理平台,其主要用途在于创建实时的数据传输管道以及流式计算应用。若要借助Kafka进行开发工作,前提条件是必须确保已经配置妥当的相关依赖,这些依赖通常以jar(Java Archive)文件格式存储。Maven作为一个Java项目管理的得力工具,能够协助开发者进行项目管理和构建过程,并且可以自动获取所需的各类库文件。在Maven框架内,我们通过在`pom.xml`文档中设定依赖关系,从而将Kafka关联的jar包引入到项目中。 文档标题所提及的"Maven配置Kafka Java开发环境所需的jar包",实际上是指需要为Maven项目设定Kafka的依赖配置。具体操作上,我们需要在项目的`pom.xml`文件中插入Kafka的相关依赖配置。例如,假设我们需要运用Apache Kafka的2.8版本,那么可以加入以下依赖配置: ```xml <dependencies> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.8.0</version> </dependency> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka_2.13</artifactId> <version>2.8.0</version> </dependency> </dependencies> ``` 在这...
手机摄像头测试方法-下载即用.zip
打开链接下载源码: https://pan.quark.cn/s/a4b39357ea24 手机相机作为现代移动设备核心功能模块的关键构成,对其质量进行严格检验显得至关重要,目的是保障相机组件能够满足既定的功能表现规范。本次探讨将聚焦于常规手机相机检测所包含的具体项目及操作方法。 首先开展镜头检测环节,其中包含杂散光干扰的评估。杂散光现象是指当捕捉强光源影像时,由于光学元件制造的不均匀性或光线折射误差,导致画面呈现模糊不清的视觉效果,即光学系统内部出现光线散射状况。杂散光检测通常借助DNPVIEWER与EIAJtestchartF两种检测设备实施评定。 随后进行清晰度测试,清晰度表征相机对图像细节的呈现效能。检测过程中常运用LightBox及ISO12233chart作为测试工具。清晰度检测旨在量化相机在特定距离条件下能够清晰分辨的线对数量,是判断相机成像锐度的重要参考依据。 几何畸变检测同样是镜头评估不可或缺的部分,该检测项目评估相机在记录直线边缘物体时,边缘线条是否发生曲线形态的扭曲变形。借助DNPVIEWER和EIAJtestchartI检测仪器能够对镜头的几何失真程度进行评定。 镜头检测还涵盖了对眩光干扰Flare的评估,这是一种当光源直接照射镜头时产生的光学现象,会对成像质量造成不利影响。采用点光源进行检测能够验证相机抵抗眩光干扰的性能。 光线泄漏检测是指判定相机在缺乏光源直接照射环境下,镜头内部是否存在光线渗漏的情况。该项检测通常需要利用光源设备实施。 CMOS图像传感器作为相机主要的光电转换元件,其功能表现评估同样具有核心意义。首先是自动白平衡AWB的检测,利用Lightbox、GretagMacbeth ColorChecker以及IMATEST软件...
YOLO26算法道路监控交通信号灯logo状态目标检测+训练好的模型+290张数据集+pyqt可视化界面.zip
附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[logo缺失(logo missing), logo正确(logo correct ok), logo方向错误(logo wrong direction), logo错误(logo wrong logo)] · 训练集:290 张 · 验证集:0 张 · 测试集:0 张 · 总计:290 张 该数据集专注于道路监控场景下的交通信号灯logo状态检测,旨在实时识别交通信号灯标志的完整性与准确性,为城市交通管理提供关键支持,有效提升道路通行效率与安全水平。 该数据集训练集规模为290张图像,提供了充足的数据样本以支持模型训练;验证集与测试集均为0张,表明数据集设计聚焦于训练环节,确保模型在有限资源下高效学习,为快速部署智能交通监控系统奠定基础。 该数据集的标注工作精准规范,各类别标注清晰准... 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 42 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.8863** mAP50-95 | 0.5727 Precision | 0.9381 Recall | 0.7841 train/box_loss | 1.1541 train/cls_loss | 1.1310 val/box_loss | 1.1534 val/cls_loss | 1.6252 【训练过程分析】 从一开始,这模型在训练过程中就显得有... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。


非技术区
