



下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 天津大學(xué)附屬中學(xué)2024-2025學(xué)年度八年級下學(xué)期3月月考?xì)v史試題(含答案)
- 2025化工設(shè)備采購銷售合同范本
- 2025企業(yè)員工勞動合同范本
- 2025企業(yè)文具采購合同范本
- 食堂勞務(wù)補(bǔ)充合同協(xié)議
- 門面出售協(xié)議合同書
- 雇傭鐘點(diǎn)工保姆合同協(xié)議
- 陵園營銷聘用合同協(xié)議
- 門窗安裝合同補(bǔ)充協(xié)議
- 隨車吊貨物轉(zhuǎn)運(yùn)合同協(xié)議
- 《建筑構(gòu)造與識圖》課程標(biāo)準(zhǔn)
- 2025年農(nóng)村商業(yè)銀行往年招聘筆試試題
- 2025年保健食品從業(yè)人員培訓(xùn)考試試題
- 2025年春新北師大版物理八年級下冊課件 第九章 機(jī)械和功 第一節(jié) 杠桿 第1課時 杠桿及其平衡條件
- 救護(hù)車租賃合同模板
- 餐飲業(yè)供應(yīng)鏈管理與采購策略
- 《家庭安全用電培訓(xùn)》課件
- 《胸腔積液》課件
- 風(fēng)電基礎(chǔ)施工方案
- ICD-10疾病編碼完整版
- 肩關(guān)節(jié)超聲檢查
評論
0/150
提交評論