当前位置: 首页>>代码示例>>C++>>正文


C++ One::PartialCopy方法代码示例

本文整理汇总了C++中One::PartialCopy方法的典型用法代码示例。如果您正苦于以下问题:C++ One::PartialCopy方法的具体用法?C++ One::PartialCopy怎么用?C++ One::PartialCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在One的用法示例。


在下文中一共展示了One::PartialCopy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Random

IterTest::IterTest()
{
	CtrlLayout(*this, "Window title");

	//generally, an iter interface needs its underlying container to live as long as interface is present.
	//no checks are performed to keep code small
	//an Iter interface will not modify the underlying container.
	//if container is changed while an Iter interface is bound to it, it may become undefined in behaviour (Vector i.e)
	//an Iter interface is always created on heap, so use means to delete it after usage, best is One<Iter<int > > foo, destroyed when scope is left

	//==========================================================================================	

	//Vector or any common linear container	

	Vector<int> vi;
	vi.SetCount(10);

	//use the explicit interface to do things
	One<Iter<int> > ii = IterCreator::GetIter(vi);
	while(ii->Next())
		ii->Get() = Random();

	//an iterator can be copied, without knowing its underlying type
	//and can be reinitiated
	One<Iter<int> > ii2 = ii->PartialCopy();
	while(ii2->Next())
		LOG(ii2->Get());

	//the const variant of Iter, ConstIter
	One<ConstIter<int> > ii3 = IterCreator::GetIter((const Vector<int>&)vi);
	while(ii3->Next())
		LOG(ii3->Get());

	FOREACH(int, e, vi)
		LOG(e);

	//and the const version
	FOREACHC(int, e, (const Vector<int>&)vi)
		LOG(e);

	//helpers to define the scope safe iterators
	ITER(int) _ii = IterCreator::GetIter(vi);
	ITERC(int) _cii = IterCreator::GetIter((const Vector<int>&)vi);

	//a macro for usual containers only without using Iter interface
	//can speed up things because no virtual stuff involved
	FOREACHCONT(int, e, vi)
		LOG(e);

	//the const variant
	FOREACHCONTC(int, e, (const Vector<int>&)vi)
		LOG(e);

	//other 'containers' also yield a Iter interface

	//usual pointer

	int in = 123;
	int* inp = &in;

	FOREACH(int, e, inp)
		LOG(e);

	FOREACHC(int, e, (const int*)inp)
		LOG(e);

	//Ptr

	EditInt ei;
	Ptr<Ctrl> eip(&ei);

	FOREACH(Ctrl, e, eip)
		e.SetData(123); 

	FOREACHC(Ctrl, e, (const Ptr<Ctrl>&)eip)
		e.GetData(); 

	//One

	One<Ctrl> oei;
	oei.Create<EditInt>();

	FOREACH(Ctrl, e, oei)
		e.SetData(123); 

	FOREACHC(Ctrl, e, (const One<Ctrl>&)oei)
		e.GetData(); 

	//Any

	Any a;
	a.Create<int>() = 345;
	One<Iter<int> > ia = IterCreator::GetIter<int>(a);
	
	FOREACH(int, e, a)
		LOG(e); 

	FOREACHC(int, e, (const Any&)a)
		LOG(e); 

//.........这里部分代码省略.........
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:101,代码来源:main.cpp


注:本文中的One::PartialCopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。