in this sectionwe will describe how type-independent algorithms (also known as generic algorithmsare written in +using the template we begin by discussing function templates then we examine class templates function templates function templates are generally very easy to write function template is not an actual functionbut instead is pattern for what could become function figure illustrates function template findmax the line containing the template declaration indicates that comparable is the template argumentit can be replaced by any type to generate function for instanceif call to findmax is made with vector as parameterthen function will be generated by replacing comparable with string figure illustrates that function templates are expanded automatically as needed it should be noted that an expansion for each new type generates additional codethis is known as code bloat when it occurs in large projects note also that the call findmax( will result in compile-time error this is because when comparable is replaced by intcellline in figure becomes illegalthere is no function defined for intcell thusit is customary to includeprior to any templatecomments that explain what assumptions are made about the template argument(sthis includes assumptions about what kinds of constructors are required because template arguments can assume any class typewhen deciding on parameterpassing and return-passing conventionsit should be assumed that template arguments are not primitive types that is why we have returned by constant reference not surprisinglythere are many arcane rules that deal with function templates most of the problems occur when the template cannot provide an exact match for the parameters but can come close (through implicit type conversionsthere must be ways to resolve /*return the maximum item in array assumes size comparable objects must provide operatorand operator*template const comparable findmaxconst vector int maxindex forint size)++ ifamaxindex ai maxindex ireturn amaxindex ]figure findmax function template