付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
PAGE
1
TransformI tor
Author: DavidAbrahams,JeremySiek,ThomasWitt
Contact: dave@bo ,
jsiek@,
witt@ive.uni-hannover.de
Organization: BoostConsulting, naUniversityOpenSystemsLab,UniversityofHanoverInstituteforTransportRailwayOperationandConstruction
Date: 2004-11-01
Copyright: CopyrightDavidAbrahams,JeremySiek,andThomasWitt2003.
:Thetransformi toradaptsani torbymodifyingtheoperator*toapplyafunctionobjecttotheresultofdereferencingthei torandreturningtheresult.
TableofContents
transform_i torsynopsistransform_i torrequirementstransform_i tormodelstransform_i toroperationsExample
transform_i torsynopsis
temte<classUnaryFunction,
classI tor,
classReference=use_default,classValue=use_default>
classtransform_i tor
{
public:
typedef/*seebelow*/value_type;typedef/*seebelow*/reference;typedef/*seebelow*/pointer;
typedefi tor_traits<I tor>::difference_typedifference_type;typedef/*seebelow*/i tor_category;
transform_i tor();
transform_i tor(I torconst&x,UnaryFunctionf);
temte<classF2,classI2,classR2,classV2>transform_i tor(
transform_i tor<F2,I2,R2,V2>const&t
PAGE
2
,typenameenable_if_convertible<I2,I tor>::type*=0 //ex-positiononly
,typenameenable_if_convertible<F2,UnaryFunction>::type*=0//ex-positiononly
);
UnaryFunctionfunctor()const;I torconst&base()const;referenceoperator*()const;
transform_i tor&operator++();transform_i tor&operator--();
private:
I torm_i tor;//expositiononlyUnaryFunctionm_f; //expositiononly
};
IfReferenceisuse_defaultthenthereferencememberoftransform_i torisresult_of<UnaryFunction(iteOtherwise,referenceisReference.
IfValueisuse_defaultthenthevalue_typememberisremove_cv<remove_reference<reference>
>::type.Otherwise,value_typeisValue.
IfItormodelsReadableLvalueItorandifItormodelsRandomAccessTraver-salItor,thenitor_categoryisconvertibletorandom_access_itor_tag.Otherwise,ifItormodelsBidirectionalTraversalItor,thenitor_categoryisconvertibletobidi-rectional_itor_tag.Otherwiseitor_categoryisconvertibletoforward_itor_tag.IfItordoesnotmodelReadableLvalueItorthenitor_categoryisconvertibletoin-put_itor_tag.
transform_itorrequirements
ThetypeUnaryFunctionmustbeAssignable,CopyConstructible,andtheexpressionf(*i)mustbevalidwherefisanobjectoftypeUnaryFunction,iisanobjectoftypeItor,andwherethetypeoff(*i)mustberesult_of<UnaryFunction(itor_traits<Itor>::reference)>::type.
TheargumentItorshallmodelReadableItor.
transform_itormodels
Theresultingtransform_itormodelsthemostrefinedofthefollowingthatisalsomodeledby
I tor.
WritableLvalueI toriftransform_i tor::referenceisanon-constreference.
ReadableLvalueI toriftransform_i tor::referenceisaconstreference.
ReadableI torotherwise.
Thetransform_itormodelsthemostrefinedstandardtraversalconceptthatismodeledbytheItorargument.
Iftransform_itorisamodelofReadableLvalueItorthenitmodelsthefollowingoriginalitorconceptsdependingonwhattheItorargumentmodels.
IfI tormodels thentransform_i tormodels
SinglePassI tor InputI tor
ForwardTraversalI tor ForwardI tor
BidirectionalTraversalI tor BidirectionalI torRandomAccessTraversalI tor RandomAccessI tor
PAGE
3
Iftransform_i tormodelsWritableLvalueI torthenitisamutablei tor(asdefinedintheoldi torrequirements).
transform_i tor<F1,X,R1,V1>isinteroperablewithtransform_i tor<F2,Y,R2,V2>
ifandonlyifXisinteroperablewithY.
transform_i toroperations
Inadditiontotheoperationsrequiredbytheconceptsmodeledbytransform_i tor,trans-form_i torprovidesthefollowingoperations.
transform_i tor();
Returns:Aninstanceoftransform_i torwithm_fandm_i tordefaultcon-structed.
transform_i tor(I torconst&x,UnaryFunctionf);
Returns:Aninstanceoftransform_i torwithm_finitializedtofandm_i tor
initializedtox.
temte<classF2,classI2,classR2,classV2>transform_i tor(
transform_i tor<F2,I2,R2,V2>const&t
,typenameenable_if_convertible<I2,I tor>::type*=0 //expo-sitiononly
,typenameenable_if_convertible<F2,UnaryFunction>::type*=0//expo-sitiononly
);
Returns:Aninstanceoftransform_i torwithm_finitializedtot.functor()and
m_i torinitializedtot.base().
Requires:OtherI torisimplicitlyconvertibletoI tor.UnaryFunctionfunctor()const;
Returns:m_f
I torconst&base()const;
Returns:m_i torreferenceoperator*()const;
Returns:m_f(*m_i tor)transform_i tor&operator++();
Effects:++m_i tor
Returns:*this
transform_i tor&operator--();
Effects:--m_i tor
Returns:*this
temte<classUnaryFunction,classI tor>transform_i tor<UnaryFunction,I tor>make_transform_i tor(I torit,UnaryFunctionfun);
Returns:Aninstanceoftransform_i tor<UnaryFunction,I tor>withm_fini-tializedtofandm_i torinitializedtox.
temte<classUnaryFunction,classI tor>transform_i tor<UnaryFunction,I tor>make_transform_i tor(I torit);
Returns:Aninstanceoftransform_i tor<UnaryFunction,I tor>withm_fde-faultconstructedandm_i torinitializedtox.
Example
Thisisasimpleexampleofusingthetransformitorsclasstogenerateitorsthatmultiply(oraddto)thevaluereturnedbydereferencingtheitor.Itwouldbecoolertouselambdalibraryinthiample.
intx[]={1,2,3,4,5,6,7,8};
constintN=sizeof(x)/sizeof(int);
typedefboost::binder1st<std::multiplies<int>>Function;
typedefboost::transform_i tor<Function,int*>doubling_i tor;
doubling_i tori(x,boost::bind1st(std::multiplies<i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2027届江苏省苏州市昆山市、太仓市物理九年级第一学期期末教学质量检测试题含解析
- 2027届河北省鸡泽县化学九年级第一学期期中考试模拟试题含解析
- 2027届四川省成都市第二十三中学九年级物理第一学期期末学业水平测试模拟试题含解析
- 2027届江苏省扬州市江都实验中学九上化学期末质量检测试题含解析
- 2027届湖北省重点中学化学九上期末考试试题含解析
- 江苏省泰州市姜堰区2027届化学九上期末综合测试模拟试题含解析
- 2027届广西贺州市九年级化学第一学期期中综合测试试题含解析
- 2026软件著作权保护策略研究及平台开发外包合作风险防范与知识产权交易市场分析
- 广西南宁市兴宁区新兴学校2027届九年级化学第一学期期中达标检测模拟试题含解析
- 海南省海口市九中学海甸分校2027届九上化学期末学业质量监测试题含解析
- GB/T 3855-2026碳纤维增强塑料树脂含量试验方法
- 灼口汤治疗灼口综合征的临床观察与疗效探究
- 儿童绘本故事《谁偷了我的饼》教学设计
- 安全生产资金保障制度范本
- 城乡融合发展政策体系研究课题申报书
- 上海核工程研究设计院股份有限公司招聘笔试题库2026
- 2025河北邢台银行股份有限公司招聘14人笔试历年典型考题及考点剖析附带答案详解
- TCSPSTC172018企业安全生产双重预防机制建设规范
- 新版胖东来考试题库及答案真题题库
- 基于血栓弹力图的骨科患者围手术期凝血功能管理方案
- 2025甘肃金川集团股份有限公司财务和审计一般管理岗位成熟人才社会招聘27人笔试历年难易错考点试卷带答案解析试卷3套
评论
0/150
提交评论