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 国际」许可协议进行许可。

posted @   CDsidi  阅读(87)  评论(4编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示
more_horiz
keyboard_arrow_up light_mode palette
选择主题