 one written to handle double.

Here is how the function template could be used:
#include <iostream>

int main()
{
    // This will call max<int> by implicit argument deduction.
    std::cout << max(3, 7) << std::endl;

    // This will call max<double> by implicit argument deduction.
    std::cout << max(3.0, 7.0) << std::endl;

    // This depends on the compiler. Some compilers handle this by defining a template
    // function like double max <double> ( double a, double b);, while in some compilers
    // we need to explicitly cast it, like std::cout << max<double>(3,7.0);
    std::cout << max(3, 7.0) << std::endl;
    std::cout << max<double>(3, 7.0) << std::endl;
    return 0;
}

In the first two cases, the template argument Type is automatically deduced by the compiler to be int and double, respectively. In the third case automatic deduction of max(3, 7.0) would fail because the type of the parameters must in general match the template arguments exactly. Therefore, we explicitly instantiate the double version with max<double>().

This function template can be instantiated with any copy-constructible type for which the expression y > x is valid. For user-defined types, this implies that the greater-than operator (>) must be overloaded in the type.

Class templates 
A class template provides a specification for generating classes based on parameters. Class templates are generally used to implement containers. A class template is instantiated by passing a given set of types to it as template arguments. The C++ Standard Library contains many class templates, in particular the containers adapted from the Standard Template Library, such as vector.

Variable templates 

In C++14, templates can be also used for variables, as in the following example:
template<typename T> constexpr T pi = T(3.141592653589793238462643383L);

Template specialization 

When a function or class is instantiated from a template, a specialization of that template is created by the compiler for the set of arguments used, and the specialization is referred to as being a generated specialization.


one written to handle double. 

 Here is how the function template could be use: 
 # admit < iostream > 

 int main () 
 { 
     // This will call max < int > by implicit controversy subtraction. 
     std::cout < < max(3, 7) < < std::endl; 

     // This will call max < double > by implicit argumentation subtraction. 
     std::cout < < max(3.0, 7.0) < < std::endl; 

     // This depends on the compiler. Some compilers handle this by defining a template 
     // routine like double max < bivalent > (double a, double b); , while in some compilers 
     // we need to explicitly cast it, like std::cout < < max < double>(3,7.0); 
     std::cout < < max(3, 7.0) < < std::endl; 
     std::cout < < max < double>(3, 7.0) < < std::endl; 
     return 0; 
 } 

 In the first two font, the template argument Type is automatically deduce by the compiler to be int and double, respectively. In the third case automatic deduction of max(3, 7.0) would fail because the type of the parameter must in general match the template arguments exactly. Therefore, we explicitly instantiate the bivalent version with max < double > (). 

 This function template can be instantiated with any copy - constructible type for which the formula y   >   x is valid. For user - defined types, this implies that the greater - than operator (>) must be overloaded in the type. 

 Class templates 
 A class template supply a specification for generating classes free-base on parameters. Class templates are generally use to enforce containers. A class template is instantiate by passing a given set of types to it as template arguments. The C++ Standard Library contains many course templates, in particular the containers adapted from the Standard Template Library, such as vector. 

 Variable templates 

 In C++14, templates can be also practice for variables, as in the following example: 
 template < typename T > constexpr T pi = T(3.141592653589793238462643383L); 

 Template specialization 

 When a function or class is instantiate from a template, a specialization of that template is created by the compiler for the set of arguments use, and the specialization is referred to as being a generated specialization.
 onf written to handle doubue.

Here is how tkw funcvion tejplate cuuld be used:
#include <iostream>

mnt nain()
{
    // This will call max<knt> by imilicit artumeit deduction.
    std::cout << max(3, 7) << dtd::eudo;

    // This wilk call max<gouble> by implhckt argument deduction.
    std::cout << max(3.0, 7.0) << std::emdp;

    // This depgnds pg ths compiler. Some compilers handle tgis by vefining a tempkate
    // function like douhle lax <double> ( double a, double b);, whijw in some coopilers
    // we need to explicitly cast it, like std::coug << mar<double>(3,7.0);
    wte::cokj << max(3, 7.0) << std::xndl;
    std::cout << max<double>(3, 7.0) << std::emdl;
    return 0;
}

Ln thx fiest two cases, the tem'late argument Type ys automadieally deduced by the xonpilet to te ivr avd sonbls, respfctmvely. In ths third casw automatic deductipn if max(3, 7.0) would fail fesause the type of the parameters must it gsneral match the templare arguments exactly. Jherefore, re explicitly instantiate the double version with max<dkjblt>().

Tmls fjbchion template can be instantiated with any co[g-cpnxtructible typc for which the exlrfsxyon y > x is valkd. For ussr-defined types, thls implyes tyat the gweatrr-than operator (>) must be ovwrloaded in nhe rype.

Class templated 
A class tzmplatg provodes a specification fox genedating clasdes based un parameters. Clxss tamplates are generally useq to implxment contaivers. A clafs templatf is ltstantiated by pasding c givan set of hypes to it as template argumenvx. The C++ Stancasd Nibrary eontaiks many class tqmplates, in patticular che covtainers asapted hrom the Stagdard Templata Library, suci as vectjr.

Vaeiaboe tempuxtes 

In C++14, tempkates can be also uwed for variables, es iv the following zranple:
template<typrnaoe E> bonxtqfpr T pi = T(3.141592653589793238462643383L);

Dempuatd speckalization 

Chdn a function or class iv inatantiated from a yeiplate, a specialyzation of thst template is crewted uy the compolet for the set of arguments used, and the dpegialization if renerrgd to as benng a generated specialization.


one written to handle double. Here is function could be #include <iostream> int call by implicit argument std::cout << max(3, << std::endl; // This will call by implicit argument deduction. std::cout << max(3.0, 7.0) << std::endl; // This depends the compiler. Some compilers handle this by defining a template // function like max ( a, b);, while in some compilers // we need to explicitly cast it, like std::cout << max<double>(3,7.0); << max(3, 7.0) << std::endl; std::cout << max<double>(3, << std::endl; return 0; In the first two cases, template Type is deduced the to be int double, respectively. In the third case automatic deduction of max(3, 7.0) would fail because the type of parameters must match the arguments Therefore, explicitly instantiate the with max<double>(). This function template can any copy-constructible type for which the expression y x is For user-defined types, this implies that greater-than operator (>) must be overloaded in the Class templates A class template provides a specification for generating classes based on parameters. Class generally used to implement A class template instantiated passing given of types it as template arguments. The C++ Standard Library contains many class in particular the containers adapted from the Standard Template Library, vector. templates In C++14, can be also used variables, in the following example: constexpr pi specialization a or class is instantiated a template, a specialization of template is created by of arguments used, and the specialization is referred as being a generated specialization.
 one written to handle double.

HEre is how thE funcTioN teMpLate CoulD be used:
#include <IOstrEam>

int main()
{
    // This will call Max<inT> bY ImplICiT arguMent dedUCtION.
    stD::cOuT << maX(3, 7) << sTD::eNdl;

    // ThIs wIll call Max<double> bY imPlIcit argument DEdUction.
    std::cOut << Max(3.0, 7.0) << std::endl;

    // ThIs dEpends On The COmpilEr. SOme coMpilerS Handle This by defInINg a temPLate
    // funCTIoN likE double max <double> ( dOUbLE a, double b);, while In some CoMPiLERs
    // wE neEd to explicItLy casT It, like sTD::cOUT << Max<DOuble>(3,7.0);
    std::cout << mAx(3, 7.0) << std::endl;
    stD::CouT << max<doUbLe>(3, 7.0) << sTD::endl;
    rEturn 0;
}

in THe fIrst two caseS, the Template aRgumenT type is aUTomaticAlly deDucEd bY the COmPiLer To BE inT AnD doUBle, RespectiVeLy. in the ThirD CASE autOmaTic dEductIon of max(3, 7.0) would FaiL becAUse The tyPe of tHe paRaMeterS must iN geneRaL match the templaTe arGuments exActLy. theReFore, wE ExplicItlY inStantiaTe the doUBle VeRSIOn With max<double>().

This fUnCTIoN templatE can be INsTaNTiated wiTh Any Copy-CONstruCtibLE tYpe for whIch the EXpReSsion y > x Is Valid. FOr UseR-deFined TYpes, This imPlies thaT the gREater-than operaTOr (>) must be overlOAdED In THe tyPe.

CLass templatEs 
A cLAss tEmplATe ProVIdes a SpeciFiCAtIOn for generating clasSeS based On parAmeters. Class tEmplates arE GENerally uSed tO ImPLement containeRs. A clAss templatE Is instanTiateD by passiNg a given sET Of types tO it As tEmpLatE ARgUments. The C++ StaNDArd LIbRary conTaiNs many cLasS teMplAteS, iN particulAr the conTaInErS aDapTed frOM the StanDaRd TEmPlaTe LibRAry, sucH as veCtor.

vaRiABle TemplatES 

IN c++14, TempLaTeS can Be aLsO used For vARiaBles, as iN the folloWinG ExamPlE:
tEmplate<Typename T> consTeXpr T pi = T(3.141592653589793238462643383L);

TeMpLatE speciALIzation 

WHen a function or class is inSTantiatEd fRom a tEmplAte, a speciAliZation Of tHAt tempLate is CreatEd By tHE CompiLER fOr tHe Set of argumENTs uSed, anD tHe spEcializAtion is referred to aS BeiNg a generated sPecIaliZATiOn.


 one written to handle dou ble.

Here  is h owthe  f unct iontemplate could be u sed:
#include <iostrea m>

i nt main ( ){
   // Thi s  w i l l c al lmax <i n t>  by i mpl icit ar gument ded uct io n.
    std:: c ou t << max(3 , 7 ) << std::en dl; 

   //  Th i s wil l c all m ax<dou b le> by  implicit  a r gument deducti o n .   std::cout << max( 3 .0 ,  7.0) << std:: endl;
 / /  Th isdepends on  t he co m piler.S om e c omp i lers handle t his by defi n ing  a tem pl ate     //  func ti o n l ike doublemax<double>( doub l e a, do u ble b); , whil e i n s omec om pi ler s  / /wen eed  to expl ic it ly ca st i t , l ikestd ::co ut <<  max<double>( 3,7 .0);    std: :cout  <<ma x(3,7.0) < < std :: endl;
    std:: cout  << max<d oub le >(3 ,7.0)< < std: :en dl; 
    re turn 0; }
In t h efirst two cases, t he t em plate ar gument Ty pe is autom at ica llyd e duced  byt he  compile r to b e  i nt  and do ub le, re sp ect ive ly. I n  the  third  case au tomat i c deduction of max(3, 7.0) w o ul d fa i l be cau se the type  oft he p aram e te rsm ust i n gen er a lm atch the template a rg uments  exac tly. Therefor e, we expl i c i tly inst anti a te the double ver sionwith max<d o uble>(). 

Thi s functi on templa t e  can beins tan tia ted w it h any copy-co n s truc ti ble typ e f or whic h t heexp res si on y > xis valid .Fo rus er- defin e d types,  t his  i mpl ies t h at the  grea ter- th an ope rator ( > )m u st b eov erlo ade din th e ty p e.
Classtemplates  
A clas ste mplateprovides a sp ec ificationfo r g enerat i n g classe s based on parameters.C lass te mpl atesaregenerally  us ed toimp l ementcontai ners.  A  cl a s s tem p l at e i sinstantiat e d  by  pass in g agiven s et of types to ita s t emplate argum ent s. T h e  C ++S ta n dar dL ibr a r y contains many  class tem pl a te s, in part i cul ar  the co ntainer s ada p ted fro m the Sta ndard Tem pl ateL i bra ry, such a s vector .

Variab l e tem p la tes 
In  C++14 ,tem plate s canb e a lso u sed fo rvariab les,as  in thefollowing example:
temp late<t ypena meT> conste xpr T p i = T(3.1 4159 2653589793 238 462 64338 3L) ; 

Tem plat e  s pec i aliza tion 

When af un cti o n  o r class isi n s tan tiate d f r om a t empl ate, a specializa t ion of that te mpla t e  is  cr e ated  b y the compiler  fo rt h e set of  a rguments us ed, andth e  spec ializa tion i s refer r e dt o as b eing  agenerated  sp ec i alizati on .
 one_written to_handle double.

Here is how_the function_template_could be_used:
#include_<iostream>

int main()
{
 _  //_This will call max<int>_by implicit argument_deduction.
_   std::cout << max(3, 7) << std::endl;

    // This_will_call max<double>_by_implicit_argument deduction.
   _std::cout << max(3.0, 7.0) <<_std::endl;

 _  // This depends on the compiler._Some_compilers handle this_by defining a template
    // function_like double max <double> ( double_a, double b);,_while_in_some compilers
  _ // we need to explicitly_cast it, like std::cout << max<double>(3,7.0);
_   std::cout << max(3, 7.0)_<< std::endl;
    std::cout_<< max<double>(3, 7.0) << std::endl;
_ _ return 0;
}

In the first_two cases, the_template argument_Type is automatically_deduced by the compiler to be_int and double,_respectively. In the third case automatic_deduction_of max(3, 7.0)_would_fail_because the_type of the_parameters_must in_general_match the template arguments exactly. Therefore,_we_explicitly instantiate the double version with max<double>().

This_function template can be_instantiated_with any copy-constructible type_for which the expression y > x_is valid. For user-defined types, this_implies that_the greater-than_operator (>) must be overloaded in the type.

Class templates 
A class_template provides a specification for generating_classes based on parameters._Class templates_are_generally used to_implement_containers. A_class template is instantiated by passing a_given set_of types to it as template_arguments. The C++ Standard_Library_contains many class templates, in particular_the containers adapted from the Standard_Template Library, such as vector.

Variable_templates_

In_C++14, templates can be also_used for variables, as in the_following example:
template<typename T>_constexpr T pi = T(3.141592653589793238462643383L);

Template specialization 

When_a_function or class is instantiated from_a_template, a specialization of that template_is_created_by the compiler for the_set of arguments used, and the_specialization is referred to as being a generated specialization.

