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;

}

只要坚持良好码风,再也不用担心别人能看懂我的代码了。

posted @ 2023-02-01 07:39  CDsidi  阅读(85)  评论(4编辑  收藏  举报