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;

}

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

原文链接: https://www.cnblogs.com/cdsidi/p/17081331.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++的妙用

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/315216

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月16日 下午1:40
下一篇 2023年2月16日 下午1:40

相关推荐