当前位置:网站首页>STL源码剖析:临时对象的代码测试和理解
STL源码剖析:临时对象的代码测试和理解
2022-07-30 05:50:00 【夕阳染色的坡道】
目的:STL的深入理解
最近看到一个非常基础的语法之类的,它也是平时人常用的临时对象,它是一种没有名的对象,(在任何 pass by value的操作都会发生copy 操作,于是形成临时对象),可以看列子,shape(2,3)或者int(8)都是生成临时对象。它相当于调用的constructor.下面列子可以看到。 对于对象myprint(),它不是函数,而是一个临时对象。它可以用于函数的参数。如下,它放入for_each中传参。
#include<vector>
#include<algorithm>
#include<iostream>
template <typename T>
class myprint
{
public:
void operator()(const T& elem)
{
std::cout << elem <<' ';}
};
int main()
{
int ia[6] = {
0,1,2,3,4,5};
std::vector<int> iv(ia, ia+6);
std::for_each(iv.begin(), iv.end(), myprint<int>());
std::cout<<std::endl;
}
运行的结果,看到myprint(),它被传入iv的参数,发生了copy。
具体大家可看侯杰翻译的STL源码剖析书。
边栏推荐
- Deploy GraphScope with Helm
- As a test leader, examine several aspects of job candidates
- Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps
- GAIA-IR: Parallelized Graph Query Engine on GraphScope
- DHCP原理与配置
- I can't hide it, I want to expose the bad things about cloud native
- From installation to compilation: 10 minutes to teach you to use and develop GraphScope locally
- 矩阵的行列式的计算及其源码
- 作为测试leader,考察求职者的几个方面
- 软件测试术语 - 场景测试
猜你喜欢

Network Protocol 03 - Routing and NAT

测试开发工程师成长日记017 - bug的生命周期

如何理解普吕克坐标(几何理解)

(GGG)JWT

I can't hide it, I want to expose the bad things about cloud native

GNNLab: A Novel GNN System Based on Spatial Sharing Ideas

用 GraphScope 像 NetworkX 一样做图分析

多线程进阶(锁策略,自旋+CAS,Synchronized,JUC,信号量)

Application of graph computing in network security analysis

02-Cycript的使用
随机推荐
Deploy GraphScope with Helm
使用 Grafana 的 Redis Data Source 插件监控 Redis
多线程进阶(CountDownLatch,死锁,线程安全集合类)
远程连接服务器的MySql
测开基础知识01
Proftpd配置文件
@Bean 与 @Component 用在同一个类上,会怎样?
MongoDB-CUD without R
Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)
Test and Development Engineer Growth Diary 009 - Environment Pai Pai Station: Development Environment, Test Environment, Production Environment, UAT Environment, Simulation Environment
彻底删除openstack中镜像的记录
多线程基础(多线程内存,安全,通信,线程池和阻塞队列)
空间直线到平面上的交点的计算证明及其源码
Ingress:从静态图分析到动态图分析
prometheus-basic_auth加密配置
黑盒测试的概念及测试方法
Test Development Engineer Growth Diary 018 - Record of Required Questions for Test Interview (Continuous Update)
I can't hide it, I want to expose the bad things about cloud native
测试开发工程师成长日记003 - 接口自动化框架搭建
测试开发工程师成长日记017 - bug的生命周期