ranges-positive.hpp algorithm /usr/include/gecode/iter.hh Gecode::Iter::Ranges::Positive Gecode Gecode::Iter Gecode::Iter::Ranges /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2008 * *Lastmodified: *$Date:2010-07-2817:35:33+0200(Wed,28Jul2010)$by$Author:schulte$ *$Revision:11294$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ #include<algorithm> namespaceGecode{namespaceIter{namespaceRanges{ template<classI,boolstrict=false> classPositive{ protected: Ii; public: Positive(void); Positive(I&i); voidinit(I&i); booloperator ()(void)const; voidoperator ++(void); intmin(void)const; intmax(void)const; unsignedintwidth(void)const; }; template<classI,boolstrict> forceinline Positive<I,strict>::Positive(void){} template<classI,boolstrict> forceinlinevoid Positive<I,strict>::init(I&i0){ i=i0; if(strict){ while(i()&&(i.max()<0))++i; }else{ while(i()&&(i.max()<=0))++i; } } template<classI,boolstrict> forceinline Positive<I,strict>::Positive(I&i){ init(i); } template<classI,boolstrict> forceinlinevoid Positive<I,strict>::operator ++(void){ ++i; } template<classI,boolstrict> forceinlinebool Positive<I,strict>::operator ()(void)const{ returni(); } template<classI,boolstrict> forceinlineint Positive<I,strict>::min(void)const{ if(strict){ returnstd::max(i.min(),1); }else{ returnstd::max(i.min(),0); } } template<classI,boolstrict> forceinlineint Positive<I,strict>::max(void)const{ returni.max(); } template<classI,boolstrict> forceinlineunsignedint Positive<I,strict>::width(void)const{ returnstatic_cast<unsignedint>(max()-min()+1); } }}} //STATISTICS:iter-any