当前位置:网站首页>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源码剖析书。
边栏推荐
猜你喜欢

Mastering JESD204B (1) – Debugging of AD6676

GAIA-IR:GraphScope 上的并行化图查询引擎

MySQL主从复制配置搭建,一步到位

STL源码剖析:迭代器的概念理解,以及代码测试。

Network Protocol 03 - Routing and NAT

Advanced multi-threading (CountDownLatch, deadlock, thread-safe collection class)

快速开发 GraphScope 图分析应用

How to save modelsim simulation data as a file

Polygon 3D(三维平面多边形)的法向量的计算(MeshLab默认的计算)

prometheus-federation-tls加密
随机推荐
(GGG)JWT
Selenium01
MongoDB-CUD without R
debian problem
Selenium02
The Force Plan Microservices | Centralized Configuration Center Config Asymmetric Encryption and Security Management
测试开发工程师成长日记003 - 接口自动化框架搭建
使用 Grafana 的 Redis Data Source 插件监控 Redis
From installation to compilation: 10 minutes to teach you to use and develop GraphScope locally
STL源码剖析:bound friend template friend代码测试和理解
Required request body is missing 问题解决
图计算在网络安全分析中的应用
Vineyard: An open source distributed in-memory data management framework
彻底删除openstack中镜像的记录
Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)
02-Use of Cycript
SE_01
舒尔补(schur completement)
Install MySQL under Linux (centos7)
Ingress:从静态图分析到动态图分析