c++的妙用
1.数列求和迭代器
2.无内存占用vector
#include<bits/stdc++.h>
using namespace std;
struct node{
int val;
node& operator = (int v){
val += v;
return *this;
}
};
struct iter{
using value_type = node;
using reference = value_type&;
using pointer = value_type*;
using iterator_category = output_iterator_tag;
using difference_type = int;
node* val;
iter(node& pos) : val(&pos){}
node& operator *(){
return *val;
}
void operator ++(){
}
};
template<typename T>
struct fancyvector{
void push_back(T val){
;
}
T back(){
return T();
}
};
int main(){
/**/
/**
* The sample of the "addable" input iterator.
*/
/*
node s = {0};
iter it(s);
cout << s.val << endl;
vector<int> v = {1, 2, 4, 5};
copy(v.begin(), v.end(), it);
cout << s.val <<endl;
*/
/**
* The sample of the non-memory-used vector.
*
*/
fancyvector<int> fv;
fv.push_back(5);
cout << fv.back() << endl;
return 0;
}
只要坚持良好码风,再也不用担心别人能看懂我的代码了。
作者:cdsidi
出处:https://www.cnblogs.com/cdsidi/p/17081331.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】